当前位置: 首页>>代码示例>>PHP>>正文


PHP FormBuilderInterface::getOption方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::getOption方法的具体用法?PHP FormBuilderInterface::getOption怎么用?PHP FormBuilderInterface::getOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormBuilderInterface的用法示例。


在下文中一共展示了FormBuilderInterface::getOption方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         if ('association' === $metadata['type']) {
             if ($metadata['associationType'] & ClassMetadata::TO_MANY) {
                 $formFieldOptions['attr']['multiple'] = true;
             }
             // supported associations are displayed using advanced JavaScript widgets
             $formFieldOptions['attr']['data-widget'] = 'select2';
         }
         if ('collection' === $metadata['fieldType']) {
             if (!isset($formFieldOptions['allow_add'])) {
                 $formFieldOptions['allow_add'] = true;
             }
             if (!isset($formFieldOptions['allow_delete'])) {
                 $formFieldOptions['allow_delete'] = true;
             }
             // The "delete_empty" option exists as of Sf >= 2.5
             if (class_exists('Symfony\\Component\\Form\\FormErrorIterator')) {
                 if (!isset($formFieldOptions['delete_empty'])) {
                     $formFieldOptions['delete_empty'] = true;
                 }
             }
         } elseif ('checkbox' === $metadata['fieldType'] && !isset($formFieldOptions['required'])) {
             $formFieldOptions['required'] = false;
         }
         if (!isset($formFieldOptions['required'])) {
             if (null !== ($guessRequired = $this->guesser->guessRequired($builder->getOption('data_class'), $name))) {
                 $formFieldOptions['required'] = $guessRequired->getValue();
             }
         }
         // Configure "placeholder" option for entity fields
         if ('association' === $metadata['type'] && $metadata['associationType'] & ClassMetadata::TO_ONE && !isset($formFieldOptions[$placeHolderOptionName = $this->getPlaceholderOptionName()]) && false === $formFieldOptions['required']) {
             $formFieldOptions[$placeHolderOptionName] = 'form.label.empty_value';
         }
         $formFieldOptions['attr']['field_type'] = $metadata['fieldType'];
         $formFieldOptions['attr']['field_css_class'] = $metadata['class'];
         $formFieldOptions['attr']['field_help'] = $metadata['help'];
         $formFieldType = $this->useLegacyFormComponent() ? $metadata['fieldType'] : $this->getFormTypeFqcn($metadata['fieldType']);
         $builder->add($name, $formFieldType, $formFieldOptions);
     }
 }
开发者ID:motvicka,项目名称:EasyAdminBundle,代码行数:50,代码来源:EasyAdminFormType.php

示例2: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('username', null, array('read_only' => 'true'));
     $builder->add('email', 'email', array('label' => 'form.email', 'read_only' => 'true', 'translation_domain' => 'FOSUserBundle'));
     $builder->add('firstName', 'text', array('label' => 'form.firstName', 'read_only' => 'true', 'translation_domain' => 'FOSUserBundle'));
     $builder->add('surname', 'text', array('label' => 'form.surname', 'read_only' => 'true', 'translation_domain' => 'FOSUserBundle'));
     $builder->add('birthdate', 'birthday', array('required' => false, 'read_only' => 'true', 'format' => 'yyyy-MM-dd', 'widget' => 'single_text', 'label' => 'form.birthdate', 'translation_domain' => 'FOSUserBundle'));
     $builder->add('mobile', null, array('required' => false, 'read_only' => 'true', 'label' => 'form.mobile', 'translation_domain' => 'FOSUserBundle'));
     $user = $this->getUser();
     $allRoles = $this->translateRoles($builder->getOption('available_roles'));
     $securityHelper = $this->securityHelper;
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($user, $allRoles, $securityHelper) {
         $person = $event->getData();
         $form = PersonResumeFormType::populateCountryStateCity($person, $event->getForm());
         $roles = PersonResumeFormType::filterRoles($person, $form, $allRoles, $securityHelper);
     });
 }
开发者ID:redelivre,项目名称:login-cidadao,代码行数:17,代码来源:PersonResumeFormType.php

示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         if ('association' === $metadata['type']) {
             $toManyAssociations = array(ClassMetadata::ONE_TO_MANY, ClassMetadata::MANY_TO_MANY);
             if (in_array($metadata['associationType'], $toManyAssociations)) {
                 $formFieldOptions['attr']['multiple'] = true;
             }
             // supported associations are displayed using advanced JavaScript widgets
             $formFieldOptions['attr']['data-widget'] = 'select2';
         }
         if ('collection' === $metadata['fieldType']) {
             if (!isset($formFieldOptions['allow_add'])) {
                 $formFieldOptions['allow_add'] = true;
             }
             if (!isset($formFieldOptions['allow_delete'])) {
                 $formFieldOptions['allow_delete'] = true;
             }
             if (version_compare(Kernel::VERSION, '2.5.0', '>=')) {
                 if (!isset($formFieldOptions['delete_empty'])) {
                     $formFieldOptions['delete_empty'] = true;
                 }
             }
         } elseif ('checkbox' === $metadata['fieldType'] && !isset($formFieldOptions['required'])) {
             $formFieldOptions['required'] = false;
         }
         if (!isset($formFieldOptions['required'])) {
             if (null !== ($guessRequired = $this->guesser->guessRequired($builder->getOption('data_class'), $name))) {
                 $formFieldOptions['required'] = $guessRequired->getValue();
             }
         }
         $formFieldOptions['attr']['field_type'] = $metadata['fieldType'];
         $formFieldOptions['attr']['field_css_class'] = $metadata['class'];
         $formFieldOptions['attr']['field_help'] = $metadata['help'];
         $formFieldType = $this->useLegacyFormComponent() ? $metadata['fieldType'] : $this->getFormTypeFqcn($metadata['fieldType']);
         $builder->add($name, $formFieldType, $formFieldOptions);
     }
 }
开发者ID:xiaoguizhidao,项目名称:EasyAdminBundle,代码行数:46,代码来源:EasyAdminFormType.php

示例4: assertFormType

 /**
  * Assert that the form element has an inner type of type $typeClass and
  * the specified options with their values.
  *
  * @param FormBuilderInterface $element
  * @param string               $typeClass FQN class
  * @param array                $options   keys are option names, values the
  *                                        expected option values
  */
 private function assertFormType(FormBuilderInterface $element, $typeClass, array $options)
 {
     $type = $element->getType()->getInnerType();
     $this->assertInstanceOf($typeClass, $type);
     foreach ($options as $option => $expected) {
         $this->assertEquals($expected, $element->getOption($option), "Option '{$option}' does not have the expected value '" . serialize($expected) . "'");
     }
 }
开发者ID:pkdevbox,项目名称:DoctrinePHPCRBundle,代码行数:17,代码来源:PHPCRTypeGuesserTest.php

示例5: fillDefaultData

 /**
  * @param mixed $data
  * @param FormBuilderInterface $form
  * @return array
  */
 public function fillDefaultData($data, FormBuilderInterface $form)
 {
     if (!$data) {
         $data = [];
     }
     foreach ($this->getLocales() as $locale) {
         $localeId = $locale->getId();
         if (!array_key_exists($localeId, $data)) {
             if ($locale->getParentLocale()) {
                 $data[$localeId] = new FallbackType(FallbackType::PARENT_LOCALE);
             } else {
                 $data[$localeId] = new FallbackType(FallbackType::SYSTEM);
             }
             if ($form->hasOption('default_callback')) {
                 /** @var \Closure $defaultCallback */
                 $defaultCallback = $form->getOption('default_callback');
                 $data[$localeId] = $defaultCallback($data[$localeId]);
             }
         }
     }
     return $data;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:27,代码来源:LocaleCollectionType.php

示例6: createPositionTab

 /**
  * @param FormBuilderInterface $builder
  *
  * @return FormBuilderInterface
  */
 private function createPositionTab(FormBuilderInterface $builder)
 {
     $source = $builder->getOption('router')->generate('clastic_backoffice_menu_item_tree', ['menuId' => $builder->getData()->getMenu()->getId()]);
     return $this->createTab($builder, 'position_tab', ['label' => 'Position'])->add('position', TreeType::class, ['source' => $source]);
 }
开发者ID:clastic,项目名称:clastic,代码行数:10,代码来源:MenuItemFormType.php

示例7: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $label = $builder->getOption('label', false);
     $builder->add('name', null, ['label' => $label ? 'Nazwa pojazdu' : false, 'attr' => ['placeholder' => 'Nazwa pojazdu']])->add('photoUrl', UrlType::class, ['label' => $label ? 'URL obrazka' : false, 'attr' => ['placeholder' => 'Podaj adres URL obrazka']])->add('description', TextareaType::class, ['label' => $label ? 'Opsi pojazdu' : false, 'attr' => ['placeholder' => 'Podaj opis pojazdu']])->add('brand', null, ['label' => $label ? 'Marka pojazdu' : false, 'attr' => ['placeholder' => 'Marka pojazdu']])->add('engine', null, ['label' => $label ? 'Silnik pojazdu' : false, 'attr' => ['placeholder' => 'Moc silnika']])->add('year', null, ['label' => $label ? 'Rok produkcji' : false, 'attr' => ['placeholder' => 'Rok produkcji']])->add('amount', null, ['label' => $label ? 'Ilośc dostępnych pojazdów' : false, 'attr' => ['placeholder' => 'Ilość dostępnych pojazdów']])->add('price', null, ['label' => $label ? 'Koszt wynajmu' : false, 'attr' => ['placeholder' => 'Koszt wynajmu (jeden dzień)']]);
 }
开发者ID:MaciejBodys,项目名称:samochody,代码行数:9,代码来源:VehicleType.php


注:本文中的Symfony\Component\Form\FormBuilderInterface::getOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。