src/Factory/FieldFactory.php
public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface
    {
        $resolver = new OptionsResolver();
        $configuration = $this->resolveConfiguration($configuration, $actionConfiguration);

        // Dispatch an event to allow dynamic changes on the form type
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $configuration['type']
        );
        $this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event);

        if (null === $event->getType()) {
            throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name);
        }
        $type = $event->getType();
        $options = array_merge($configuration['options'], $event->getOptions());

        if (!key_exists($type, $this->fieldsMapping)) {
            $type = 'auto';
        }
        $field = $this->instanciateField($name, $type);
        $field->configureOptions($resolver, $actionConfiguration);

        try {
            $field->setOptions($resolver->resolve($options));
        } catch (\Exception $exception) {
            throw new Exception(
                'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(),
                $exception->getCode(),
                $exception
            );
        }
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $type,
            $field
        );
        $this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event);

        return $field;
    }
public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface
    {
        $resolver = new OptionsResolver();
        $configuration = $this->resolveConfiguration($configuration, $actionConfiguration);

        // Dispatch an event to allow dynamic changes on the form type
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $configuration['type']
        );
        $this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event);

        if (null === $event->getType()) {
            throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name);
        }
        $type = $event->getType();
        $options = array_merge($configuration['options'], $event->getOptions());

        if (!key_exists($type, $this->fieldsMapping)) {
            $type = 'auto';
        }
        $field = $this->instanciateField($name, $type);
        $field->configureOptions($resolver, $actionConfiguration);

        try {
            $field->setOptions($resolver->resolve($options));
        } catch (\Exception $exception) {
            throw new Exception(
                'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(),
                $exception->getCode(),
                $exception
            );
        }
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $type,
            $field
        );
        $this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event);

        return $field;
    }
public function create ( string $ name , array $ configuration , ActionConfiguration $ actionConfiguration ) : FieldInterface { $ resolver = new OptionsResolver ( ) ; $ configuration = $ this -> resolveConfiguration ( $ configuration , $ actionConfiguration ) ; // Dispatch an event to allow dynamic changes on the form type $ event = new FieldEvent ( $ actionConfiguration -> getAdminName ( ) , $ actionConfiguration -> getActionName ( ) , $ name , $ actionConfiguration -> getAdminConfiguration ( ) -> get ( 'entity' ) , $ configuration [ 'type' ] ) ; $ this -> eventDispatcher -> dispatch ( Events :: FIELD_PRE_CREATE , $ event ) ; if ( null === $ event -> getType ( ) ) { throw new FieldTypeNotFoundException ( $ event -> getAdminName ( ) , $ event -> getActionName ( ) , $ name ) ; } $ type = $ event -> getType ( ) ; $ options = array_merge ( $ configuration [ 'options' ] , $ event -> getOptions ( ) ) ; if ( ! key_exists ( $ type , $ this -> fieldsMapping ) ) { $ type = 'auto' ; } $ field = $ this -> instanciateField ( $ name , $ type ) ; $ field -> configureOptions ( $ resolver , $ actionConfiguration ) ; try { $ field -> setOptions ( $ resolver -> resolve ( $ options ) ) ; } catch ( \ Exception $ exception ) { throw new Exception ( 'An error has occurred when resolving the options for the field "' . $ name . '": ' . $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ exception ) ; } $ event = new FieldEvent ( $ actionConfiguration -> getAdminName ( ) , $ actionConfiguration -> getActionName ( ) , $ name , $ actionConfiguration -> getAdminConfiguration ( ) -> get ( 'entity' ) , $ type , $ field ) ; $ this -> eventDispatcher -> dispatch ( Events :: FIELD_POST_CREATE , $ event ) ; return $ field ; }
Create a new field instance according to the given configuration.

@param string              $name
@param array               $configuration
@param ActionConfiguration $actionConfiguration

@return FieldInterface

@throws Exception
Create a new field instance according to the given configuration .