src/Forms/FormBuilder.php
public function add(FieldTypeInterface $field): FormBuilderInterface
    {
        /** @var BaseType $field */
        $opts = $this->validateOptions(array_merge([
            'errors' => $this->form->getOption('errors'),
            'theme' => $this->form->getOption('theme')
        ], $field->getOptions()), $field);
        $field->setLocale($this->form->getLocale());
        $field->setOptions($opts);
        $field->setForm($this->form);
        $field->setViewFactory($this->form->getViewer());
        $field->setResourceTransformerFactory($this->form->getResourceTransformerFactory());

        // DTO
        if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
            $this->dataMapperManager->mapFromObjectToField($this->dataClass, $field);
        }

        // Check if section instance already exists on the form.
        // If not, create a new section instance.
        if ($this->form->repository()->hasGroup($field->getOption('group'))) {
            // The section/group instance is already registered, just fetch it.
            $section = $this->form->repository()->getGroup($field->getOption('group'));
        } else {
            // No defined group. Let's create an instance so we can attach
            // the field to it right after.
            $section = new Section($field->getOption('group'));
        }

        // Setup group/section default view.
        $section->setTheme($this->form->getTheme());
        $section->setView('form.group');

        // Add the field first to section instance.
        // Then pass both objects to the repository.
        $section->addItem($field);
        $this->form->repository()->addField($field, $section);

        return $this;
    }
public function add(FieldTypeInterface $field): FormBuilderInterface
    {
        /** @var BaseType $field */
        $opts = $this->validateOptions(array_merge([
            'errors' => $this->form->getOption('errors'),
            'theme' => $this->form->getOption('theme')
        ], $field->getOptions()), $field);
        $field->setLocale($this->form->getLocale());
        $field->setOptions($opts);
        $field->setForm($this->form);
        $field->setViewFactory($this->form->getViewer());
        $field->setResourceTransformerFactory($this->form->getResourceTransformerFactory());

        // DTO
        if (! is_null($this->dataClass) && is_object($this->dataClass) && $field->getOption('mapped')) {
            $this->dataMapperManager->mapFromObjectToField($this->dataClass, $field);
        }

        // Check if section instance already exists on the form.
        // If not, create a new section instance.
        if ($this->form->repository()->hasGroup($field->getOption('group'))) {
            // The section/group instance is already registered, just fetch it.
            $section = $this->form->repository()->getGroup($field->getOption('group'));
        } else {
            // No defined group. Let's create an instance so we can attach
            // the field to it right after.
            $section = new Section($field->getOption('group'));
        }

        // Setup group/section default view.
        $section->setTheme($this->form->getTheme());
        $section->setView('form.group');

        // Add the field first to section instance.
        // Then pass both objects to the repository.
        $section->addItem($field);
        $this->form->repository()->addField($field, $section);

        return $this;
    }
public function add ( FieldTypeInterface $ field ) : FormBuilderInterface { /** @var BaseType $field */ $ opts = $ this -> validateOptions ( array_merge ( [ 'errors' => $ this -> form -> getOption ( 'errors' ) , 'theme' => $ this -> form -> getOption ( 'theme' ) ] , $ field -> getOptions ( ) ) , $ field ) ; $ field -> setLocale ( $ this -> form -> getLocale ( ) ) ; $ field -> setOptions ( $ opts ) ; $ field -> setForm ( $ this -> form ) ; $ field -> setViewFactory ( $ this -> form -> getViewer ( ) ) ; $ field -> setResourceTransformerFactory ( $ this -> form -> getResourceTransformerFactory ( ) ) ; // DTO if ( ! is_null ( $ this -> dataClass ) && is_object ( $ this -> dataClass ) && $ field -> getOption ( 'mapped' ) ) { $ this -> dataMapperManager -> mapFromObjectToField ( $ this -> dataClass , $ field ) ; } // Check if section instance already exists on the form. // If not, create a new section instance. if ( $ this -> form -> repository ( ) -> hasGroup ( $ field -> getOption ( 'group' ) ) ) { // The section/group instance is already registered, just fetch it. $ section = $ this -> form -> repository ( ) -> getGroup ( $ field -> getOption ( 'group' ) ) ; } else { // No defined group. Let's create an instance so we can attach // the field to it right after. $ section = new Section ( $ field -> getOption ( 'group' ) ) ; } // Setup group/section default view. $ section -> setTheme ( $ this -> form -> getTheme ( ) ) ; $ section -> setView ( 'form.group' ) ; // Add the field first to section instance. // Then pass both objects to the repository. $ section -> addItem ( $ field ) ; $ this -> form -> repository ( ) -> addField ( $ field , $ section ) ; return $ this ; }
Add a field to the current form instance.

@param FieldTypeInterface $field

@return FormBuilderInterface
Add a field to the current form instance .