Model/ExtendedFieldModel.php
public function saveEntity($entity, $unlock = true)
    {
        if (!$this->isExtendedField($entity)) {
            parent::saveEntity($entity, $unlock);

            return;
        }

        if (!$entity instanceof LeadField) {
            throw new MethodNotAllowedHttpException(['LeadEntity']);
        }

        $isNew = $entity->getId() ? false : true;
        $this->setTimestamps($entity, $isNew, $unlock);
        $alias = $entity->getAlias();
        if ($isNew) {
            if (empty($alias)) {
                $alias = $entity->getName();
            }

            // clean the alias
            $alias = $this->cleanAlias($alias, 'f_', 25);

            // make sure alias is not already taken
            $repo      = $this->getRepository();
            $aliases   = $repo->getAliases($entity->getId(), false, true, $entity->getObject());
            $aliasTag  = 1;
            $testAlias = $alias;
            while (in_array($testAlias, $aliases)) {
                $testAlias = $alias.$aliasTag++;
            }
            $entity->setAlias($testAlias);
        }

        // Special treatment for time (same as core).
        if ('time' == $entity->getType()) {
            $entity->setIsListable(false);
        }

        // Presave and postsave (same as core, but using OverrideLeadFieldRepository).
        $event = $this->dispatchEvent('pre_save', $entity, $isNew);
        $this->getRepository()->saveEntity($entity);
        $this->dispatchEvent('post_save', $entity, $isNew, $event);

        // Update order of the other fields (same as core).
        $this->reorderFieldsByEntity($entity);
    }
public function saveEntity($entity, $unlock = true)
    {
        if (!$this->isExtendedField($entity)) {
            parent::saveEntity($entity, $unlock);

            return;
        }

        if (!$entity instanceof LeadField) {
            throw new MethodNotAllowedHttpException(['LeadEntity']);
        }

        $isNew = $entity->getId() ? false : true;
        $this->setTimestamps($entity, $isNew, $unlock);
        $alias = $entity->getAlias();
        if ($isNew) {
            if (empty($alias)) {
                $alias = $entity->getName();
            }

            // clean the alias
            $alias = $this->cleanAlias($alias, 'f_', 25);

            // make sure alias is not already taken
            $repo      = $this->getRepository();
            $aliases   = $repo->getAliases($entity->getId(), false, true, $entity->getObject());
            $aliasTag  = 1;
            $testAlias = $alias;
            while (in_array($testAlias, $aliases)) {
                $testAlias = $alias.$aliasTag++;
            }
            $entity->setAlias($testAlias);
        }

        // Special treatment for time (same as core).
        if ('time' == $entity->getType()) {
            $entity->setIsListable(false);
        }

        // Presave and postsave (same as core, but using OverrideLeadFieldRepository).
        $event = $this->dispatchEvent('pre_save', $entity, $isNew);
        $this->getRepository()->saveEntity($entity);
        $this->dispatchEvent('post_save', $entity, $isNew, $event);

        // Update order of the other fields (same as core).
        $this->reorderFieldsByEntity($entity);
    }
public function saveEntity ( $ entity , $ unlock = true ) { if ( ! $ this -> isExtendedField ( $ entity ) ) { parent :: saveEntity ( $ entity , $ unlock ) ; return ; } if ( ! $ entity instanceof LeadField ) { throw new MethodNotAllowedHttpException ( [ 'LeadEntity' ] ) ; } $ isNew = $ entity -> getId ( ) ? false : true ; $ this -> setTimestamps ( $ entity , $ isNew , $ unlock ) ; $ alias = $ entity -> getAlias ( ) ; if ( $ isNew ) { if ( empty ( $ alias ) ) { $ alias = $ entity -> getName ( ) ; } // clean the alias $ alias = $ this -> cleanAlias ( $ alias , 'f_' , 25 ) ; // make sure alias is not already taken $ repo = $ this -> getRepository ( ) ; $ aliases = $ repo -> getAliases ( $ entity -> getId ( ) , false , true , $ entity -> getObject ( ) ) ; $ aliasTag = 1 ; $ testAlias = $ alias ; while ( in_array ( $ testAlias , $ aliases ) ) { $ testAlias = $ alias . $ aliasTag ++ ; } $ entity -> setAlias ( $ testAlias ) ; } // Special treatment for time (same as core). if ( 'time' == $ entity -> getType ( ) ) { $ entity -> setIsListable ( false ) ; } // Presave and postsave (same as core, but using OverrideLeadFieldRepository). $ event = $ this -> dispatchEvent ( 'pre_save' , $ entity , $ isNew ) ; $ this -> getRepository ( ) -> saveEntity ( $ entity ) ; $ this -> dispatchEvent ( 'post_save' , $ entity , $ isNew , $ event ) ; // Update order of the other fields (same as core). $ this -> reorderFieldsByEntity ( $ entity ) ; }
Save an extended field.

Alterations to core:
The save uses OverrideLeadFieldRepository if the field is extended.
We also prevent alias collisions (as it wouldn't be a column definition).

@param object $entity
@param bool   $unlock

@throws DBALException
@throws DriverException
@throws \Doctrine\DBAL\Schema\SchemaException
@throws \Mautic\CoreBundle\Exception\SchemaException
Save an extended field .