本文整理汇总了PHP中Symfony\Component\Form\FormInterface::add方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::add方法的具体用法?PHP FormInterface::add怎么用?PHP FormInterface::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: manageLinkTypeRelatedFields
/**
* Add the types related to the LinkType value.
*
* @param $linkType
* @param $locale
* @param FormBuilderInterface|FormInterface $form
* @param FormBuilderInterface $builder
*/
protected function manageLinkTypeRelatedFields($linkType, $locale, $form, FormBuilderInterface $builder)
{
$form->remove('route');
$form->remove('url');
$form->remove('attachedWidget');
$form->remove('viewReference');
$form->remove('locale');
switch ($linkType) {
case Link::TYPE_VIEW_REFERENCE:
$locale = $locale ?: $this->requestStack->getCurrentRequest()->getLocale();
$form->add('viewReference', ChoiceType::class, ['label' => 'form.link_type.view_reference.label', 'required' => true, 'attr' => ['novalidate' => 'novalidate'], 'placeholder' => 'form.link_type.view_reference.blank', 'choices' => $this->viewReferenceRepository->getChoices($locale), 'choices_as_values' => true, 'vic_vic_widget_form_group_attr' => ['class' => 'vic-form-group']])->add('locale', ChoiceType::class, ['label' => 'form.link_type.locale.label', 'choices' => array_combine($this->availableLocales, $this->availableLocales), 'attr' => ['data-refreshOnChange' => 'true']]);
break;
case Link::TYPE_ROUTE:
$form->add('route', null, ['label' => 'form.link_type.route.label', 'vic_vic_widget_form_group_attr' => ['class' => 'vic-form-group'], 'required' => true, 'attr' => ['novalidate' => 'novalidate', 'placeholder' => 'form.link_type.route.placeholder']])->add('route_parameters', JsonType::class, ['label' => 'form.link_type.route_parameters.label', 'vic_vic_widget_form_group_attr' => ['class' => 'vic-form-group'], 'required' => true, 'attr' => ['novalidate' => 'novalidate', 'placeholder' => 'form.link_type.route_parameters.placeholder']]);
break;
case Link::TYPE_URL:
$form->add('url', null, ['label' => 'form.link_type.url.label', 'vic_vic_widget_form_group_attr' => ['class' => 'vic-form-group'], 'required' => true, 'attr' => ['novalidate' => 'novalidate', 'placeholder' => 'form.link_type.url.placeholder']]);
break;
case Link::TYPE_WIDGET:
$form->add('attachedWidget', EntityType::class, ['label' => 'form.link_type.attachedWidget.label', 'placeholder' => 'form.link_type.attachedWidget.blank', 'class' => 'VictoireWidgetBundle:Widget', 'vic_vic_widget_form_group_attr' => ['class' => 'vic-form-group'], 'required' => true, 'attr' => ['novalidate' => 'novalidate']]);
break;
case Link::TYPE_NONE:
case null:
$form->remove('target');
break;
}
}
示例2: buildForm
/**
* @param FormInterface $form
* @param string|null $data
*/
private function buildForm(FormInterface $form, $data)
{
$form->remove('value')->remove('from')->remove('to');
if ($data === null || in_array($data, DateTimeFilter::getSimpleTypes(), true)) {
$form->add('value', $this->innerType);
} elseif (in_array($data, DateTimeFilter::getCompoundTypes())) {
$form->add('from', $this->innerType)->add('to', $this->innerType);
}
}
示例3: buildForm
/**
* @param FormInterface $form
* @param string|null $data
*/
private function buildForm(FormInterface $form, $data)
{
$form->remove('value')->remove('from')->remove('to');
if ($data === null || in_array($data, NumberFilter::getSimpleTypes(), true)) {
$form->add('value', NumberForm::class);
} elseif (in_array($data, NumberFilter::getCompoundTypes())) {
$form->add('from', NumberForm::class)->add('to', NumberForm::class);
}
}
示例4: addElements_Prof_Matiere
public function addElements_Prof_Matiere(FormInterface $form, Matiere $matiere = null)
{
$submit = $form->get('ajouter');
$form->remove('ajouter');
$form->add('matiere', EntityType::class, ['class' => 'EDTBundle:Matiere', 'choice_label' => 'nom', 'placeholder' => '-- choisir une matière --', 'multiple' => false, 'mapped' => true, 'data' => $matiere]);
$profs = array();
if ($matiere) {
$repo = $this->em->getRepository('UserBundle:Professeur');
$profs = $repo->createQueryBuilder('p')->leftJoin('p.prof_matieres', 'pm')->addSelect('pm')->leftJoin('pm.matiere', 'm')->addSelect('m')->where('m.id = :id_m')->setParameter('id_m', $matiere->getId())->getQuery()->getResult();
}
$form->add('professeur', EntityType::class, ['class' => 'UserBundle:Professeur', 'choice_label' => 'username', 'placeholder' => '--choisir une matière en premier --', 'choices' => $profs, 'multiple' => false]);
$form->add($submit);
}
示例5: update
/**
* Update form fields
*
* @param FormInterface $form
* @param null $data
*/
private function update(FormInterface $form, $data)
{
if (!is_array($data) || !array_key_exists('owner_types', $data)) {
return;
}
if ($this->isJoint) {
$form->add($this->factory->createNamed('owner_types', 'choice', $data['owner_types'], array('mapped' => false, 'choices' => $this->getOwnerTypesChoices(), 'expanded' => true, 'multiple' => true, 'data' => $data['owner_types'])));
if (is_array($data) && (array_key_exists('other_contact', $data) || in_array(ClientAccountOwner::OWNER_TYPE_OTHER, $data['owner_types']))) {
$form->add($this->factory->createNamed('other_contact', new OtherAccountOwnerFormType($this->getOtherContactData())));
}
} else {
$form->add($this->factory->createNamed('owner_types', 'choice', $data, array('mapped' => false, 'choices' => $this->getOwnerTypesChoices(), 'expanded' => true, 'multiple' => false, 'data' => $data)));
}
}
示例6: addFilterFields
/**
* Adds filter fields to form.
*
* @param FormInterface $form The filter form.
*/
private function addFilterFields(FormInterface $form)
{
$config = $this->getConfig($this->fieldName);
$form->add('field', 'hidden', array('data' => $config['field']));
$form->add('operator', 'choice', array('choices' => $this->getOperators($config['filter']), 'required' => true, 'translation_domain' => 'Admingenerator'));
$isCollectionType = array_key_exists('type', $config['options']) && array_key_exists('options', $config['options']) && array_key_exists('prototype', $config['options']);
if ($isCollectionType) {
$formType = $config['options']['type'];
$formOptions = $config['options']['options'];
} else {
$formType = $config['form'];
$formOptions = $config['options'];
}
$form->add('value', $formType, array_merge($formOptions, array('required' => true)));
}
示例7: mergeConstraints
/**
* Merges constraints from the form with constraints in the class metaData
*
* @param FormInterface $form
*/
public function mergeConstraints(FormInterface &$form)
{
$metaData = null;
$dataClass = $form->getConfig()->getDataClass();
if ($dataClass != '') {
$metaData = $this->validator->getMetadataFor($dataClass);
}
if ($metaData instanceof ClassMetadata) {
/**
* @var FormInterface $child
*/
foreach ($form->all() as $child) {
$options = $child->getConfig()->getOptions();
$name = $child->getConfig()->getName();
$type = $child->getConfig()->getType()->getName();
if (isset($options['constraints'])) {
$existingConstraints = $options['constraints'];
$extractedConstraints = $this->extractPropertyConstraints($name, $metaData);
// Merge all constraints
$options['constraints'] = array_merge($existingConstraints, $extractedConstraints);
}
$form->add($name, $type, $options);
}
}
}
示例8: buildField
/**
* Build form field
*
* @param DocumentType $document Document type
* @param FormInterface $form Form
* @param string $name Field name
* @param string $type Field type
* @param array $options Options
* @param mixed $submittedData Submitted data
* @return void
*/
public function buildField(DocumentType $document, FormInterface $form, $name, $type, array $options = [], $submittedData = null)
{
$options['type'] = $document->getChildForm($options['options']['data_class']);
$options['allow_add'] = true;
$options['allow_delete'] = true;
$form->add($name, $type, $options);
}
示例9: buildForm
/**
* @param FormInterface $form
* @param string|null $data
*/
private function buildForm(FormInterface $form, $data)
{
$form->remove('value');
if ($data === null || in_array($data, TextFilter::getSimpleTypes(), true)) {
$form->add('value', TextForm::class);
}
}
示例10: addUniversityForm
private function addUniversityForm(FormInterface $form, $university)
{
$form->add($this->factory->createNamed('university', 'entity', $university, array('class' => 'AppBundle:University', 'mapped' => false, 'auto_initialize' => false, 'label' => 'label.university', 'placeholder' => 'placeholder.university', 'query_builder' => function (EntityRepository $repository) {
$qb = $repository->createQueryBuilder('university')->orderBy('university.name', 'ASC');
return $qb;
})));
}
示例11: addConfigurationFields
/**
* @param FormInterface $form
* @param string $ruleType
* @param array $data
*/
protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = [])
{
/** @var RuleCheckerInterface $checker */
$checker = $this->checkerRegistry->get($ruleType);
$configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, ['auto_initialize' => false]);
$form->add($configurationField);
}
示例12: buildField
/**
* Build form field
*
* @param DocumentType $document Document type
* @param FormInterface $form Form
* @param string $name Field name
* @param string $type Field type
* @param array $options Options
* @param mixed $submittedData Submitted data
* @return void
*/
public function buildField(DocumentType $document, FormInterface $form, $name, $type, array $options = [], $submittedData = null)
{
if ('strictboolean' === $type) {
$options['submitted_data'] = $submittedData;
}
$form->add($name, $type, $options);
}
示例13: attached
protected function attached($presenter)
{
if ($presenter instanceof Presenter) {
$this->form->add('_signal', 'Arachne\\Forms\\Extension\\Application\\Type\\SignalType', ['mapped' => false, 'data' => $this->lookupPath('Nette\\Application\\UI\\Presenter') . self::NAME_SEPARATOR . 'submit']);
}
parent::attached($presenter);
}
示例14: addFields
/**
* Adds column and filters sub forms
*
* @param FormInterface $form
* @param FormFactoryInterface $factory
* @param string|null $entity
*/
protected function addFields($form, $factory, $entity = null)
{
$config = $form->getConfig();
$groupingColumnChoiceType = $config->getOption('grouping_column_choice_type');
if ($groupingColumnChoiceType) {
$form->add($factory->createNamed('grouping', 'oro_query_designer_grouping', null, array('mapped' => false, 'column_choice_type' => $groupingColumnChoiceType, 'entity' => $entity, 'auto_initialize' => false)));
}
$columnChoiceType = $config->getOption('column_column_choice_type');
if ($columnChoiceType) {
$form->add($factory->createNamed('column', 'oro_query_designer_column', null, array('mapped' => false, 'column_choice_type' => $columnChoiceType, 'entity' => $entity, 'auto_initialize' => false)));
}
$filterColumnChoiceType = $config->getOption('filter_column_choice_type');
if ($filterColumnChoiceType) {
$form->add($factory->createNamed('filter', 'oro_query_designer_filter', null, array('mapped' => false, 'column_choice_type' => $filterColumnChoiceType, 'entity' => $entity, 'auto_initialize' => false)));
}
}
示例15: updateForm
/**
* @param FormInterface $form
* @param UserEmailOrigin $emailOrigin
*/
protected function updateForm(FormInterface $form, UserEmailOrigin $emailOrigin)
{
if (!empty($emailOrigin->getAccessToken())) {
$form->add('checkFolder', 'button', ['label' => $this->translator->trans('oro.email.retrieve_folders.label'), 'attr' => ['class' => 'btn btn-primary']])->add('folders', 'oro_email_email_folder_tree', ['label' => $this->translator->trans('oro.email.folders.label'), 'attr' => ['class' => 'folder-tree'], 'tooltip' => $this->translator->trans('oro.email.folders.tooltip')]);
$form->remove('check');
}
}