src/CoreBundle/EventListener/DcGeneral/Table/MetaModel/TableNamePrefixingListener.php
public function handle(EncodePropertyValueFromWidgetEvent $event)
    {
        if (!$this->wantToHandle($event) || ($event->getProperty() !== 'tableName')) {
            return;
        }

        // See #49.
        $tableName = strtolower($event->getValue());

        if (!strlen($tableName)) {
            throw new \RuntimeException('Table name not given');
        }

        // Force mm_ prefix.
        if (substr($tableName, 0, 3) !== 'mm_') {
            $tableName = 'mm_' . $tableName;
        }

        $dataProvider = $event->getEnvironment()->getDataProvider('tl_metamodel');

        try {
            // New model, ensure the table does not exist.
            if (!$event->getModel()->getId()) {
                $this->tableManipulator->checkTableDoesNotExist($tableName);
            } else {
                // Edited model, ensure the value is unique and then that the table does not exist.
                $oldVersion = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($event->getModel()->getId()));

                if ($oldVersion->getProperty('tableName') !== $event->getModel()->getProperty('tableName')) {
                    $this->tableManipulator->checkTableDoesNotExist($tableName);
                }
            }
        } catch (\Exception $exception) {
            throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception);
        }

        $event->setValue($tableName);
    }
public function handle(EncodePropertyValueFromWidgetEvent $event)
    {
        if (!$this->wantToHandle($event) || ($event->getProperty() !== 'tableName')) {
            return;
        }

        // See #49.
        $tableName = strtolower($event->getValue());

        if (!strlen($tableName)) {
            throw new \RuntimeException('Table name not given');
        }

        // Force mm_ prefix.
        if (substr($tableName, 0, 3) !== 'mm_') {
            $tableName = 'mm_' . $tableName;
        }

        $dataProvider = $event->getEnvironment()->getDataProvider('tl_metamodel');

        try {
            // New model, ensure the table does not exist.
            if (!$event->getModel()->getId()) {
                $this->tableManipulator->checkTableDoesNotExist($tableName);
            } else {
                // Edited model, ensure the value is unique and then that the table does not exist.
                $oldVersion = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($event->getModel()->getId()));

                if ($oldVersion->getProperty('tableName') !== $event->getModel()->getProperty('tableName')) {
                    $this->tableManipulator->checkTableDoesNotExist($tableName);
                }
            }
        } catch (\Exception $exception) {
            throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception);
        }

        $event->setValue($tableName);
    }
public function handle ( EncodePropertyValueFromWidgetEvent $ event ) { if ( ! $ this -> wantToHandle ( $ event ) || ( $ event -> getProperty ( ) !== 'tableName' ) ) { return ; } // See #49. $ tableName = strtolower ( $ event -> getValue ( ) ) ; if ( ! strlen ( $ tableName ) ) { throw new \ RuntimeException ( 'Table name not given' ) ; } // Force mm_ prefix. if ( substr ( $ tableName , 0 , 3 ) !== 'mm_' ) { $ tableName = 'mm_' . $ tableName ; } $ dataProvider = $ event -> getEnvironment ( ) -> getDataProvider ( 'tl_metamodel' ) ; try { // New model, ensure the table does not exist. if ( ! $ event -> getModel ( ) -> getId ( ) ) { $ this -> tableManipulator -> checkTableDoesNotExist ( $ tableName ) ; } else { // Edited model, ensure the value is unique and then that the table does not exist. $ oldVersion = $ dataProvider -> fetch ( $ dataProvider -> getEmptyConfig ( ) -> setId ( $ event -> getModel ( ) -> getId ( ) ) ) ; if ( $ oldVersion -> getProperty ( 'tableName' ) !== $ event -> getModel ( ) -> getProperty ( 'tableName' ) ) { $ this -> tableManipulator -> checkTableDoesNotExist ( $ tableName ) ; } } } catch ( \ Exception $ exception ) { throw new \ RuntimeException ( $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ exception ) ; } $ event -> setValue ( $ tableName ) ; }
Called by tl_metamodel.tableName onsave_callback.

Prefixes the table name with mm_ if not provided by the user as such.
Checks if the table name is legal to the DB.

@param EncodePropertyValueFromWidgetEvent $event The event.

@return void

@throws \RuntimeException On invalid table names.
Called by tl_metamodel . tableName onsave_callback .