buildForm

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2012-10-28
552815
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $seller = $this->seller;

        $builder
            ->add('sellerHubRef', 'entity', array(
                'class'    => 'HarvestCloudCoreBundle:SellerHubRef',
                'property' => 'hubName',
                'label'    => 'Hub',
                'query_builder' => function(SellerHubRefRepository $er) use ($seller) {
                    return $er->createQueryBuilder('shr')
                        ->where('shr.seller = :seller')
                        ->setParameter('seller', $seller)
                    ;
                },
            ))
            ->add('day_of_week_numbers', 'choice', array(
                'choices'   => DayOfWeek::getChoices(),
                'multiple'  => true,
                'expanded'  => true,
                'label'     => 'Days of Week',
            ))
            ->add('start_time', 'choice', array(
                'choices'   => WindowMaker::getStartTimeChoices(),
            ))
            ->add('end_time', 'choice', array(
                'choices'   => WindowMaker::getEndTimeChoices(),
            ))
            ->add('delivery_type', 'choice', array(
                'choices' => array(
                  HubWindow::DELIVERY_TYPE_PICKUP   => 'Pickup',
                  HubWindow::DELIVERY_TYPE_DELIVERY => 'Delivery',
                ),
                'multiple'  => false,
                'expanded'  => true,
            ))
        ;
    }
654170
protected function buildForm()
    {
        $this->form = Yii::createObject(array_merge([
            'scenario' => $this->scenario,
            'parent_id' => $this->parent_id,
            'parentTariff' => $this->parentTariff,
            'tariff' => $this->tariff,
        ], $this->getFormOptions()));
    }
820836
public function build($build_path = null, ConnectionInterface $connection = null, array $event_handlers = [])
    {
        $builders = $this->getBuilders($build_path, $connection, $event_handlers);

        foreach ($builders as $builder) {
            $builder->preBuild();
        }

        foreach ($this->types as $type) {
            foreach ($builders as $builder) {
                $builder->buildType($type);
            }
        }

        foreach ($builders as $builder) {
            $builder->postBuild();
        }
    }
688824
protected function doBuild()
    {
        switch ($this->props['attribs']['type']) {
            case 'checkbox':
                $return = $this->buildCheckbox();
                break;
            case 'html':
                $return = $this->props['attribs']['value'];
                break;
            case 'radio':
                $return = $this->buildRadio();
                break;
            case 'select':
                $return = $this->buildSelect();
                break;
            case 'textarea':
                $return = $this->buildTextarea();
                break;
            case 'button':
            case 'reset':
            case 'submit':
                $return = $this->buildButton();
                break;
            case 'static':
                $return = $this->buildStatic();
                break;
            default:
                $return = $this->buildDefault();
        }
        return $return;
    }
743705
public function buildForm(array $form, FormStateInterface $form_state)
    {
        $form['#form_horizontal'] = true;

        $form['mail'] = [
            '#type' => 'textfield',
            '#title' => $this->t("E-mail address"),
            '#description' => $this->t("You must supply the same address as the one given in your account."),
            '#maxlength' => EMAIL_MAX_LENGTH,
            '#required' => true,
        ];

        $form['actions'] = [
            '#type' => 'actions',
            'submit' => [
                '#type' => 'submit',
                '#value' => $this->t('Send my request'),
            ],
        ];

        return $form;
    }
523451
protected function buildForm()
    {
        // Create countries and shipping modules list
        $countries = [0 => '   '];

        $list = CountryQuery::create()->find();

        /** @var \Thelia\Model\Country $item */
        foreach ($list as $item) {
            $countries[$item->getId()] = $item->getTitle();
        }

        asort($countries);

        $countries[0] = Translator::getInstance()->trans("All countries");

        $modules = [0 => '   '];

        $list = ModuleQuery::create()->filterByActivate(BaseModule::IS_ACTIVATED)->filterByType(BaseModule::DELIVERY_MODULE_TYPE)->find();

        /** @var Module $item */
        foreach ($list as $item) {
            $modules[$item->getId()] = $item->getTitle();
        }

        asort($modules);

        $modules[0] = Translator::getInstance()->trans("All shipping methods");

        $this->formBuilder
            ->add(
                'code',
                'text',
                [
                    'constraints' => [
                        new NotBlank(),
                        new Callback(
                            [
                                "methods" => [
                                    [$this, "checkDuplicateCouponCode"],
                                ],
                                "groups" => "creation",
                            ]
                        ),
                        new Callback(
                            [
                                "methods" => [
                                    [$this, "checkCouponCodeChangedAndDoesntExists"],
                                ],
                                "groups" => "update",
                            ]
                        ),
                    ]
                ]
            )
            ->add(
                'title',
                'text',
                [
                    'constraints' => [
                        new NotBlank(),
                    ]
                ]
            )
            ->add(
                'shortDescription',
                'text'
            )
            ->add(
                'description',
                'textarea'
            )
            ->add(
                'type',
                'text',
                [
                    'constraints' => [
                        new NotBlank(),
                        new NotEqualTo(
                            [
                                'value' => -1,
                            ]
                        ),
                    ]
                ]
            )
            ->add(
                'isEnabled',
                'text',
                []
            )
            ->add(
                'startDate',
                'text',
                [
                    'constraints' => [
                        new Callback(
                            [
                                "methods" => [
                                    [$this, "checkLocalizedDate"],
                                ],
                            ]
                        ),
                    ]
                ]
            )
            ->add(
                'expirationDate',
                'text',
                [
                    'constraints' => [
                        new NotBlank(),
                        new Callback(
                            [
                                "methods" => [
                                    [$this, "checkLocalizedDate"],
                                    [$this, "checkConsistencyDates"],
                                ],
                            ]
                        ),
                    ]
                ]
            )
            ->add(
                'isCumulative',
                'text',
                []
            )
            ->add(
                'isRemovingPostage',
                'text',
                []
            )
            ->add(
                'freeShippingForCountries',
                'choice',
                [
                    'multiple' => true,
                    'choices'  => $countries
                ]
            )
            ->add(
                'freeShippingForModules',
                'choice',
                [
                    'multiple' => true,
                    'choices'  => $modules
                ]
            )
            ->add(
                'isAvailableOnSpecialOffers',
                'text',
                []
            )
            ->add(
                'maxUsage',
                'text',
                [
                    'constraints' => [
                        new NotBlank(),
                        new GreaterThanOrEqual(['value' => -1]),
                    ]
                ]
            )
            ->add(
                'perCustomerUsageCount',
                'choice',
                [
                    'multiple' => false,
                    'required' => true,
                    'choices'  => [
                        1 => Translator::getInstance()->trans('Per customer'),
                        0 => Translator::getInstance()->trans('Overall'),
                    ]
                ]
            )
            ->add(
                'locale',
                'hidden',
                [
                    'constraints' => [
                        new NotBlank(),
                    ]
                ]
            )
            ->add(
                'coupon_specific',
                'collection',
                [
                    'allow_add'    => true,
                    'allow_delete' => true,
                ]
            )
        ;
    }
546889
public function build()
    {
        $options = $this->suppliedOptions;

        //set the title if it doesn't exist
        $options['title'] = $this->validator->arrayGet($options, 'title', $options['field_name']);

        //run the visible property closure if supplied
        $visible = $this->validator->arrayGet($options, 'visible');

        if (is_callable($visible)) {
            $options['visible'] = $visible($this->config->getDataModel()) ? true : false;
        }

        //run the editable property's closure if supplied
        $editable = $this->validator->arrayGet($options, 'editable');

        if (isset($editable) && is_callable($editable)) {
            $options['editable'] = $editable($this->config->getDataModel());
        }

        $this->suppliedOptions = $options;
    }
520524
protected function buildSelect()
    {
        if (!empty($this->props['attribs']['multiple']) && \substr($this->props['attribs']['name'], -2) !== '[]') {
            $this->props['attribs']['name'] .= '[]';
        }
        if ($this->props['attribs']['required'] && !$this->props['attribs']['multiple'] && $this->props['options']) {
            /*
                Check for an empty-value "Select" option
                If no empty option, add one
            */
            $firstValue = $this->props['options'][0]['attribs']['value'];
            $emptyValues = array('','--','select');
            if (!\in_array(\strtolower($firstValue), $emptyValues)) {
                $selectOption = array(
                    'attribs' => array(
                        'value' => '',
                        'disabled' => true,
                        'selected' => empty($this->props['values']),
                    ),
                    'label' => 'Select',
                );
                \array_unshift($this->props['options'], $selectOption);
            }
        }
        // build select input
        $this->props['attribs']['type'] = null;
        $attribStrings = $this->buildAttribStrings($this->props);
        $props = \array_merge($this->props, $attribStrings);
        if (empty($props['input'])) {
            $this->props['input'] = Html::buildTag(
                $props['tagname'],
                $props['attribs'],
                "\n".$this->buildSelectOptions($this->props['options'], $this->props['values'])
            );
            $props['input'] = $this->buildInputGroup();
        }
        return $this->props['tagOnly']
            ? $props['input']
            : Str::quickTemp($props['template'], $props);
    }
297666
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['plugin'] !== $this->plugin) {
            return;
        }

        $this->buildPluginForm($builder, $options);
    }
1209045
function build(): string
    {
        if ($this->host !== null && $this->preferredFormat === static::ABSOLUTE) {
            return $this->buildAbsolute();
        } else {
            return $this->buildRelative();
        }
    }
1301056
protected function createComponentAddForm(): Form
	{
		$form = $this->formFactory->create();
		$form->addProtection();

		$form->addText('username', 'cms.user.username')
			->setRequired();
		$form->addText('firstName', 'cms.user.firstName');
		$form->addText('surname', 'cms.user.surname');
		$form->addText('email', 'cms.user.email')
			->setRequired()
			->addRule(Form::EMAIL);
		$form->addPhone('phone', 'cms.user.phone');
		$form->addSelectUntranslated('language', 'cms.user.language', $this->localeService->allowed, 'form.none');

		$form->addMultiSelectUntranslated('roles', 'cms.permissions.roles', $this->orm->aclRoles->fetchPairs($this->user->isAllowed('dockbar.settings.permissions.superadmin', 'view')))
			->setRequired();

		if ($this->configurator->sendNewUserPassword) {
			$form->addCheckbox('generatePassword', 'cms.user.generatePassword')
				->addCondition($form::EQUAL, false)
				->toggle('password')
				->toggle('passwordVerify');
		} else {
			$form->addHidden('generatePassword', false);
		}

		$form->addPassword('password', 'cms.user.newPassword')
			->setOption('id', 'password')
			->addConditionOn($form['generatePassword'], Form::EQUAL, false)
			->setRequired()
			->addRule(Form::MIN_LENGTH, null, $this->minPasswordLength)
			->endCondition();
		$form->addPassword('passwordVerify', 'cms.user.passwordVerify')
			->setOption('id', 'passwordVerify')
			->addConditionOn($form['generatePassword'], Form::EQUAL, false)
			->setRequired()
			->addRule(Form::EQUAL, null, $form['password'])
			->endCondition();

		$form->addSubmit('save', 'form.save');
		$form->addLink('back', 'form.back', $this->getBacklink());

		$form->onSuccess[] = [$this, 'addFormSucceeded'];
		return $form;
	}
408594
protected function build()
    {
        $mail = clone $this;
        $mail->setHeader('Message-ID', $this->getRandomId());

        $cursor = $mail;
        if ($mail->attachments) {
            $tmp = $cursor->setContentType('multipart/mixed');
            $cursor = $cursor->addPart();
            foreach ($mail->attachments as $value) {
                $tmp->addPart($value);
            }
        }

        if ($mail->htmlBody !== '') {
            $tmp = $cursor->setContentType('multipart/alternative');
            $cursor = $cursor->addPart();
            $alt = $tmp->addPart();
            if ($mail->inlines) {
                $tmp = $alt->setContentType('multipart/related');
                $alt = $alt->addPart();
                foreach ($mail->inlines as $value) {
                    $tmp->addPart($value);
                }
            }
            $alt->setContentType('text/html', 'UTF-8')
                ->setEncoding(\preg_match('#[^\n]{990}#', $mail->htmlBody)
                    ? self::ENCODING_QUOTED_PRINTABLE
                    : (\preg_match('#[\x80-\xFF]#', $mail->htmlBody) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
                ->setBody($mail->htmlBody);
        }

        $text = $mail->getBody();
        $mail->setBody('');
        $cursor->setContentType('text/plain', 'UTF-8')
            ->setEncoding(\preg_match('#[^\n]{990}#', $text)
                ? self::ENCODING_QUOTED_PRINTABLE
                : (\preg_match('#[\x80-\xFF]#', $text) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
            ->setBody($text);

        return $mail;
    }
1110657
function traitEntityAttachHtml_formBuild() {
        $this->traitEntity_formBuild();
        $this->form->putTbSubmit($this->traitEntityAttach_btnText())
                   ->addClass('btn btn-' . $this->traitEntityAttach_btnClass());
    }
1016951
protected function buildDataForm(FormBuilderInterface $builder)
    {
        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function (FormEvent $event) {
                $form = $event->getForm();
                /** @var User $user */
                $user = $event->getData();

                $dataOptions = [
                    'label' => false,
                    'widget_form_group_attr' => false,
                    'horizontal_input_wrapper_class' => false,
                    'family' => 'User',
                ];

                if (!$user->getData()) {
                    $dataOptions['data'] = $this->familyRegistry->getFamily('User')->createData();
                }
                /** @var FormBuilderInterface $infoTab */
                $infoTab = $form->get('__tab_info');
                $infoTab->add('data', DataType::class, $dataOptions);
            }
        );
    }
1089409
public function doBuild()
    {
        $output = parent::build();
        if ($this->form && $this->form->status['submitted'] && !$this->props['isValid']) {
            // did not validate -> add hidden field
            $noticeName = $this->attribs['name'].'_notice';
            $this->debug->warn('buildControl', $this->form->buildControl);
            $output .= $this->form->buildControl->build(array(
                'type' => 'hidden',
                'name' => $noticeName,
                'value' => $this->val(),
            ));
        }
        return $output;
    }
684443
function traitEntity_formBuild() {
        $form_class = $this->getClassForm();
        $form       = new $form_class(static::getEntity());
        $form->setModel($this->model);
        $form->setAction($_SERVER['REQUEST_URI']);
        $form->setAction(\Request::getUri());
        //        dd($form);
        //::factory($this->model)
        //билдим форму, если надо - переопределяем метод "traitEntityFormBuild"
        $this->traitEntity_formAddFields($form);
        $form->addRecursiveFilter('trim');
        //        $form_builder->form->setVendor($this->getVendor())
        //                           ->setEntity($this->getEntity())
        //                           ->setDataId(isset($this->model->id) ? $this->model->id : 0);
        $this->form = $form;
        $this->traitEntity_formBuildAfter();
    }
926984
public function build()
    {
        if (empty($this->groups)) {
            Throw new FormDesignerException('Your form has no groups to show. Add groups and try again.');
        }

        if (!$this->html->getId()) {
            Throw new FormDesignerException('There is no unique form id set. Each FormDesigner form needs it\'s unique id');
        }

        // Handle global container errors
        $this->handleGlobalContainerErrors();

        // Handle display mode
        $this->handleDisplayMode();

        // Control html container
        $html = '';

        // Create hidden field with unique session token
        if (!empty($this->token)) {
            $html .= '<input type="hidden" name="' . $this->token['name'] . '" value="' . $this->token['token'] . '">';
        }

        foreach ($this->groups as $group) {
            $html .= $this->buildGroup($group, [], $this->data, $this->errors);
        }

        $this->html->addInner($html);

        return $this->html->build();
    }