示例#1
0
 /**
  * Stores a button for later rendering
  *
  * @param ButtonBuilder        $buttonBuilder
  * @param FormBuilderInterface $form
  * @param string               $position
  */
 protected function storeButton(ButtonBuilder $buttonBuilder, FormBuilderInterface $form, $position)
 {
     if (!isset($this->buttons[$form->getName()])) {
         $this->buttons[$form->getName()] = array();
     }
     $this->buttons[$form->getName()][$position] = $buttonBuilder;
 }
示例#2
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['text_field']) {
         $options['text_field'] = $builder->getName() . '_name';
     }
     $builder->setAttribute('text_field', $options['text_field']);
     $hidden_name = $builder->getName();
     $text_name = $options['text_field'];
     $repo = $this->em->getRepository($options['class']);
     $builder->add($text_name, 'text', array('attr' => array('class' => 'autocomplete_input'), 'mapped' => $options['other_allowed']))->add($hidden_name, 'hidden', array('data_class' => $options['class'], 'empty_data' => null))->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($repo, $hidden_name, $text_name) {
         $data = $event->getData();
         $obj = null;
         if (is_numeric($data[$hidden_name])) {
             $obj = $repo->findOneBy(array('id' => $data[$hidden_name], 'name' => $data[$text_name]));
         }
         if (!$obj && !empty($data[$text_name])) {
             $obj = $repo->findOneByName($data[$text_name]);
         }
         if (is_null($obj)) {
             $event->setData(array($hidden_name => null, $text_name => $data[$text_name]));
         } else {
             $event->setData(array($hidden_name => $obj, $text_name => $obj->getName()));
         }
     });
 }
示例#3
0
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('valueType', ValueProviderType::class, ['label' => 'attribute.value_type', 'attr' => ['placeholder' => 'form.value_type.placeholder', 'help_text' => 'form.value_type.help_text']])->add('displayName', TextType::class, ['label' => 'attribute.display_name', 'attr' => ['class' => 'slugify', 'data-slugify-target' => '.slugify-target-' . $builder->getName(), 'data-slugify-separator' => '_', 'placeholder' => 'form.display_name.placeholder', 'help_text' => 'form.display_name.help_text', 'widget_col' => 6]])->add('name', TextType::class, ['label' => 'attribute.name', 'attr' => ['class' => 'slugify-target-' . $builder->getName(), 'placeholder' => 'form.name.placeholder', 'help_text' => 'form.name.help_text', 'widget_col' => 6]])->add('description', TextType::class, ['required' => false, 'label' => 'attribute.description', 'attr' => ['help_text' => 'form.description.help_text']])->add('sort', IntegerType::class, ['label' => 'attribute.sort', 'attr' => ['help_text' => 'form.sort.help_text', 'widget_col' => 2], 'empty_data' => 0, 'required' => false])->add('required', ChoiceType::class, ['choices' => [false => 'Not required', true => 'Required'], 'label' => 'Required', 'required' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $attribute = $event->getData();
         $form = $event->getForm();
         if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
             // TODO Use Symfony's CollectionType here
             $form->add('options', CollapsibleCollectionType::class, ['allow_add' => true, 'allow_delete' => true, 'type' => OptionType::class]);
         }
     });
 }
 /**
  * Adds a CSRF field to the form when the CSRF protection is enabled.
  *
  * @param FormBuilderInterface $builder The form builder
  * @param array                $options The options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['csrf_protection']) {
         return;
     }
     $builder->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType()))));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->checkOptions($options);
     $fieldName = $builder->getName();
     $className = $options['translation_data_class'];
     $id = $options['object_id'];
     $locales = $options['locales'];
     $userLocale = $this->userLocale;
     // fetch data for each locale on this field of the object
     $translations = $this->translatablefieldmanager->getTranslatedFields($className, $fieldName, $id, $locales, $userLocale);
     // 'populate' fields by *hook on form generation
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($fieldName, $locales, $translations) {
         $form = $event->getForm();
         foreach ($locales as $locale) {
             $data = array_key_exists($locale, $translations) && array_key_exists($fieldName, $translations[$locale]) ? $translations[$locale][$fieldName] : NULL;
             $form->add($locale, 'text', ['label' => false, 'data' => $data]);
         }
         // extra field for twig rendering
         $form->add('currentFieldName', 'hidden', array('data' => $fieldName));
     });
     // submit
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($fieldName, $className, $id, $locales, $userLocale) {
         $form = $event->getForm();
         $this->translatablefieldmanager->persistTranslations($form, $className, $fieldName, $id, $locales, $userLocale);
     });
 }
示例#6
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // Creatd with createNamed('', ...) so likely an API request, might
     // need to make this a little better in the future
     $buildTabs = $builder->getName() === '' ? false : $options['build_tabs'];
     $tabsData = $options['tabs_data'];
     $formType = $builder->getType()->getInnerType();
     $tabDefaults = ['inherit_data' => true];
     foreach ($tabsData as $name => $data) {
         $tabOptions = array_merge($tabDefaults, $data);
         $forceTab = isset($data['force_tab']) ? $data['force_tab'] : false;
         // Remove unused option
         if ($forceTab) {
             unset($tabOptions['force_tab']);
         }
         // Build Tab
         if ($buildTabs || $forceTab) {
             $parent = $builder->create($name, 'tab', $tabOptions);
             $builder->add($parent);
             // Just add it to the main form
         } else {
             $parent = $builder;
         }
         // Get method name
         $method = sprintf('build%sForm', ucfirst($name));
         if (!method_exists($formType, $method)) {
             throw new \InvalidArgumentException(sprintf('Method "%s" does not exist in "%s"', $method, get_class($formType)));
         }
         // call buildTabNameForm
         call_user_func([$formType, $method], $parent, $options, $builder->getData());
     }
 }
示例#7
0
 /**
  * Adds a CSRF field to the form when the CSRF protection is enabled.
  *
  * @param FormBuilderInterface $builder The form builder
  * @param array                $options The options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['csrf_protection']) {
         return;
     }
     $builder->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_token_manager'], $options['csrf_token_id'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType())), $options['csrf_message'], $this->translator, $this->translationDomain));
 }
示例#8
0
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('valueType', 'value_provider', ['label' => 'attribute.value_type', 'attr' => ['placeholder' => 'form.value_type.placeholder', 'help_text' => 'form.value_type.help_text']])->add('displayName', TextType::class, ['label' => 'attribute.display_name', 'attr' => ['class' => 'slugify', 'data-slugify-target' => '.slugify-target-' . $builder->getName(), 'data-slugify-separator' => '_', 'placeholder' => 'form.display_name.placeholder', 'help_text' => 'form.display_name.help_text', 'widget_col' => 6]])->add('name', TextType::class, ['label' => 'attribute.name', 'attr' => ['class' => 'slugify-target-' . $builder->getName(), 'placeholder' => 'form.name.placeholder', 'help_text' => 'form.name.help_text', 'widget_col' => 6]])->add('description', TextType::class, ['required' => false, 'label' => 'attribute.description', 'attr' => ['help_text' => 'form.description.help_text']])->add('sort', IntegerType::class, ['label' => 'attribute.sort', 'attr' => ['help_text' => 'form.sort.help_text', 'widget_col' => 2], 'empty_data' => 0])->add('required', ChoiceType::class, ['choices' => [false => 'Not required', true => 'Required'], 'label' => 'Required', 'required' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $attribute = $event->getData();
         $form = $event->getForm();
         if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
             $form->add('options', 'collapsible_collection', ['allow_add' => true, 'allow_delete' => true, 'type' => $this->optionType]);
         }
         if ($attribute && $attribute->getValueType() == 'nested') {
             $form->add('allowedSchemas', 'entity', ['class' => $this->schemaClass, 'property' => 'displayName', 'query_builder' => function (EntityRepository $er) {
                 return $er->createQueryBuilder('t')->orderBy('t.displayName', 'ASC');
             }, 'by_reference' => false, 'expanded' => true, 'multiple' => true, 'label' => $this->translator->trans('attribute.allowed_schemas'), 'attr' => ['help_text' => $this->translator->trans('form.allowed_schemas.help_text')]]);
         }
     });
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CollectionUploadSubscriber($builder->getName(), $options, $this->storage));
     if (!$builder->hasAttribute('prototype')) {
         $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options']));
         $builder->setAttribute('prototype', $prototype->getForm());
     }
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options['lastname_options']['required'] = $options['required'];
     $options['firstname_options']['required'] = $options['required'];
     if (!isset($options['options']['error_bubbling'])) {
         $options['options']['error_bubbling'] = $options['error_bubbling'];
     }
     if (empty($options['lastname_name'])) {
         $options['lastname_name'] = $builder->getName() . '01';
     }
     if (empty($options['firstname_name'])) {
         $options['firstname_name'] = $builder->getName() . '02';
     }
     $builder->add($options['lastname_name'], 'text', array_merge($options['options'], $options['lastname_options']))->add($options['firstname_name'], 'text', array_merge($options['options'], $options['firstname_options']));
     $builder->setAttribute('lastname_name', $options['lastname_name']);
     $builder->setAttribute('firstname_name', $options['firstname_name']);
     $builder->addEventSubscriber(new \Eccube\Event\FormEventSubscriber());
 }
示例#11
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // if($options['uploadConfig']['saveOriginal']){
     //     $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
     // }
     // var_dump($builder->getDataMapper());exit;
     if ($options['uploadConfig']['saveOriginal']) {
         $builder->add($options['uploadConfig']['saveOriginal'], 'text', array('attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
     }
     $builder->add($builder->getName(), 'text', array('attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $fileOptions = $options['file_widget_options'];
     $field = empty($options['field']) ? $builder->getName() : $options['field'];
     $builder->add('id', 'hidden');
     $builder->add('delete', 'hidden', array('data' => 0));
     $builder->add('file', 'file', $fileOptions);
     $builder->addViewTransformer(new FileRepositoryViewTransformer($this->uploadManager, $options['repository_type'], $options['subdirectory'], $this->uploadRequestType));
     $builder->addModelTransformer(new FileRepositoryModelTransformer($this->uploadManager, $options['repository_type'], $options['subdirectory'], $this->uploadRequestType));
     $builder->addEventSubscriber(new FileRepositoryFormSubscriber($this->uploadManager, $options['repository_type'], $field));
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options['zip01_options']['required'] = $options['required'];
     $options['zip02_options']['required'] = $options['required'];
     // required の場合は NotBlank も追加する
     if ($options['required']) {
         $options['options']['constraints'] = array_merge(array(new Assert\NotBlank(array())), $options['options']['constraints']);
     }
     if (!isset($options['options']['error_bubbling'])) {
         $options['options']['error_bubbling'] = $options['error_bubbling'];
     }
     if (empty($options['zip01_name'])) {
         $options['zip01_name'] = $builder->getName() . '01';
     }
     if (empty($options['zip02_name'])) {
         $options['zip02_name'] = $builder->getName() . '02';
     }
     $builder->add($options['zip01_name'], 'text', array_merge_recursive($options['options'], $options['zip01_options']))->add($options['zip02_name'], 'text', array_merge_recursive($options['options'], $options['zip02_options']));
     $builder->setAttribute('zip01_name', $options['zip01_name']);
     $builder->setAttribute('zip02_name', $options['zip02_name']);
 }
 /**
  * @param \Symfony\Component\Form\FormBuilderInterface $builder
  * @param \Symfony\Component\Form\FormBuilderInterface $fileBuilder
  * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $fileEventDispatcher
  * @param \FSi\Bundle\DoctrineExtensionsBundle\Form\EventListener\FileSubscriber $fileSubscriber
  * @param \FSi\Bundle\DoctrineExtensionsBundle\Form\EventListener\RemovableFileSubscriber $removableFileSubscriber
  */
 function it_should_build_form_remove_original_listener_and_register_own_listener(FormBuilderInterface $builder, FormBuilderInterface $fileBuilder, EventDispatcherInterface $fileEventDispatcher, FileSubscriber $fileSubscriber, RemovableFileSubscriber $removableFileSubscriber)
 {
     $builder->getName()->willReturn('file_field_name');
     $builder->add('file_field_name', 'file_field_type', array('label' => false, 'error_bubbling' => true, 'some_file_field_option' => 'file_option_value'))->shouldBeCalled();
     $builder->add('remove_field_name', 'remove_field_type', array('required' => false, 'label' => 'fsi_removable_file.remove', 'mapped' => false, 'translation_domain' => 'FSiDoctrineExtensionsBundle', 'some_remove_field_option' => 'remove_option_value'))->shouldBeCalled();
     $builder->get('file_field_name')->willReturn($fileBuilder);
     $fileBuilder->getEventDispatcher()->willReturn($fileEventDispatcher);
     $fileEventDispatcher->getListeners(FormEvents::PRE_SUBMIT)->willReturn(array(array($fileSubscriber)));
     $fileEventDispatcher->removeSubscriber($fileSubscriber)->shouldBeCalled();
     $builder->addEventSubscriber($removableFileSubscriber)->shouldBeCalled();
     $this->buildForm($builder, array('file_type' => 'file_field_type', 'file_options' => array('some_file_field_option' => 'file_option_value'), 'remove_name' => 'remove_field_name', 'remove_type' => 'remove_field_type', 'remove_options' => array('some_remove_field_option' => 'remove_option_value')));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $isDefaultTranslation = 'defaultLocale' === $builder->getName();
     // Custom mapper for translations
     if (!$isDefaultTranslation) {
         $builder->setDataMapper(new GedmoTranslationMapper());
     }
     foreach ($options['locales'] as $locale) {
         if (isset($options['fields_options'][$locale])) {
             $builder->add($locale, 'a2lix_translationsFields', array('fields' => $options['fields_options'][$locale], 'translation_class' => $options['translation_class'], 'inherit_data' => $isDefaultTranslation));
         }
     }
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // Simple way is enough
     if (!$options['inherit_data']) {
         $builder->setDataMapper(new GedmoTranslationMapper());
         $builder->addEventSubscriber($this->translationsListener);
     } else {
         if (!$options['translatable_class']) {
             throw new \Exception("If you want include the default locale with translations locales, you need to fill the 'translatable_class' option");
         }
         $childrenOptions = $this->translationForm->getChildrenOptions($options['translatable_class'], $options);
         $defaultLocale = (array) $this->translationForm->getGedmoTranslatableListener()->getDefaultLocale();
         $builder->add('defaultLocale', 'a2lix_translationsLocales_gedmo', array('locales' => $defaultLocale, 'fields_options' => $childrenOptions, 'inherit_data' => true));
         $builder->add($builder->getName(), 'a2lix_translationsLocales_gedmo', array('locales' => array_diff($options['locales'], $defaultLocale), 'fields_options' => $childrenOptions, 'inherit_data' => false, 'translation_class' => $this->translationForm->getTranslationClass($options['translatable_class'])));
     }
 }
示例#17
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (isset($options['include'])) {
         $this->include = $options['include'];
     }
     if (isset($options['multiple'])) {
         $this->multiple = $options['multiple'];
     }
     $placeholder = $this->multiple ? 'brad, kierra, ...' : null;
     $transformer = new PlayerTransformer();
     $builder->add($builder->create('players', 'text', array('attr' => array('class' => 'player-select', 'placeholder' => $placeholder), 'label' => ucfirst($builder->getName()) . ': ', 'required' => false))->addViewTransformer($transformer));
     // True if the client provided the recipient usernames instead of IDs
     // (to support non-JS browsers)
     $builder->add('ListUsernames', 'hidden', array('attr' => array('class' => 'player-select-type'), 'data' => true));
     $builder->addEventListener(FormEvents::SUBMIT, array($this, 'onSubmit'));
 }
示例#18
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $help = $options['help'];
     if ($help === null && $builder->hasParent()) {
         $parentClass = $builder->getParent()->getOption('data_class');
         $fieldName = $builder->getName();
         if ($parentClass !== null) {
             $reflector = new ReflectionProperty($parentClass, $fieldName);
             $annot = $this->reader->getPropertyAnnotation($reflector, 'Tg\\OkoaBundle\\Form\\Annotation\\Help');
             if ($annot !== null) {
                 $help = $annot->value;
             }
         }
     }
     $builder->setAttribute('help', $help);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // if($options['uploadConfig']['saveOriginal']){
     //     $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
     // }
     // var_dump($builder->getDataMapper());exit;
     // if($options['uploadConfig']['saveOriginal']){
     //     $builder->add($options['uploadConfig']['saveOriginal'], 'text', array(
     //         // 'inherit_data' => true,
     //         // 'property_path' => $options['uploadConfig']['saveOriginal'],
     //         'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
     // }
     $builder->add($builder->getName(), 'collection', array('allow_add' => function (Options $options, $value) {
         return true;
     }, 'allow_delete' => function (Options $options, $value) {
         return true;
     }, 'options' => array('attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;padding: 0; position: absolute;'))));
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options['tel01_options']['required'] = $options['required'];
     $options['tel02_options']['required'] = $options['required'];
     $options['tel03_options']['required'] = $options['required'];
     // required の場合は NotBlank も追加する
     if ($options['required']) {
         $options['options']['constraints'] = array_merge(array(new Assert\NotBlank(array())), $options['options']['constraints']);
     }
     if (!isset($options['options']['error_bubbling'])) {
         $options['options']['error_bubbling'] = $options['error_bubbling'];
     }
     // nameは呼び出しもので定義したものを使う
     if (empty($options['tel01_name'])) {
         $options['tel01_name'] = $builder->getName() . '01';
     }
     if (empty($options['tel02_name'])) {
         $options['tel02_name'] = $builder->getName() . '02';
     }
     if (empty($options['tel03_name'])) {
         $options['tel03_name'] = $builder->getName() . '03';
     }
     // 全角英数を事前に半角にする
     $builder->addEventSubscriber(new \Eccube\EventListener\ConvertKanaListener());
     $builder->add($options['tel01_name'], 'text', array_merge_recursive($options['options'], $options['tel01_options']))->add($options['tel02_name'], 'text', array_merge_recursive($options['options'], $options['tel02_options']))->add($options['tel03_name'], 'text', array_merge_recursive($options['options'], $options['tel03_options']));
     $builder->setAttribute('tel01_name', $options['tel01_name']);
     $builder->setAttribute('tel02_name', $options['tel02_name']);
     $builder->setAttribute('tel03_name', $options['tel03_name']);
     // todo 変
     $builder->addEventListener(FormEvents::POST_BIND, function ($event) use($builder) {
         $form = $event->getForm();
         $count = 0;
         if ($form[$builder->getName() . '01']->getData() != '') {
             $count++;
         }
         if ($form[$builder->getName() . '02']->getData() != '') {
             $count++;
         }
         if ($form[$builder->getName() . '03']->getData() != '') {
             $count++;
         }
         if ($count != 0 && $count != 3) {
             // todo メッセージをymlに入れる
             $form[$builder->getName() . '01']->addError(new FormError('全て入力してください。'));
         }
     });
     $builder->addEventSubscriber(new \Eccube\Event\FormEventSubscriber());
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (isset($options['include'])) {
         $this->include = $options['include'];
     }
     if (isset($options['multiple'])) {
         $this->multiple = $options['multiple'];
     }
     if ($this->include && !$this->multiple) {
         throw new \LogicException("You can't include an object in a single selection!");
     }
     $builderName = ucfirst($builder->getName());
     // TODO: Use a more accurate placeholder
     $placeholder = $this->multiple ? 'brad, kierra, ...' : null;
     if ($this->include) {
         $exclude = $this->include->getType() . ':' . $this->include->getId();
     } else {
         $exclude = null;
     }
     // Model IDs that will be manipulated by javascript
     $builder->add('ids', 'hidden', array('attr' => array('class' => 'select2-compatible', 'data-exclude' => $exclude, 'data-label' => $builderName, 'data-multiple' => $this->multiple, 'data-required' => $options['required'])));
     // Model name inputs that will be edited by users if javascript is
     // disabled
     foreach ($this->types as $type) {
         $pluralType = $this->multiple ? Inflector::pluralize($type) : $type;
         $label = count($this->types) > 1 ? "{$builderName} {$pluralType}" : $builderName;
         $builder->add($builder->create($type, 'text', array('attr' => array('class' => 'model-select', 'data-type' => $type, 'placeholder' => $placeholder), 'label' => $label, 'required' => false)));
     }
     if ($this->multiple) {
         $transformer = new MultipleAdvancedModelTransformer($this->types);
         if ($this->include) {
             $transformer->addInclude($this->include);
         }
     } else {
         $transformer = new SingleAdvancedModelTransformer($this->types);
     }
     $builder->addViewTransformer($transformer);
     // Make sure we can change the values provided by the user
     $builder->setDataLocked(false);
 }
示例#22
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options['tel01_options']['required'] = $options['required'];
     $options['tel02_options']['required'] = $options['required'];
     $options['tel03_options']['required'] = $options['required'];
     if (!isset($options['options']['error_bubbling'])) {
         $options['options']['error_bubbling'] = $options['error_bubbling'];
     }
     if (empty($options['tel01_name'])) {
         $options['tel01_name'] = $builder->getName() . '01';
     }
     if (empty($options['tel02_name'])) {
         $options['tel02_name'] = $builder->getName() . '02';
     }
     if (empty($options['tel03_name'])) {
         $options['tel03_name'] = $builder->getName() . '03';
     }
     $builder->add($options['tel01_name'], 'text', array_merge($options['options'], $options['tel01_options']))->add($options['tel02_name'], 'text', array_merge($options['options'], $options['tel02_options']))->add($options['tel03_name'], 'text', array_merge($options['options'], $options['tel03_options']));
     $builder->setAttribute('tel01_name', $options['tel01_name']);
     $builder->setAttribute('tel02_name', $options['tel02_name']);
     $builder->setAttribute('tel03_name', $options['tel03_name']);
     $builder->addEventListener(FormEvents::POST_BIND, function ($event) use($builder) {
         $form = $event->getForm();
         $count = 0;
         if ($form[$builder->getName() . '01']->getData() != '') {
             $count++;
         }
         if ($form[$builder->getName() . '02']->getData() != '') {
             $count++;
         }
         if ($form[$builder->getName() . '03']->getData() != '') {
             $count++;
         }
         if ($count != 0 && $count != 3) {
             $form[$builder->getName() . '01']->addError(new FormError('全て入力してください。'));
         }
     });
     $builder->addEventSubscriber(new \Eccube\Event\FormEventSubscriber());
 }
 /**
  * Builds form
  *
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     foreach ($this->translationsHelper->getLanguages() as $locale => $name) {
         $builder->add($locale, @$options['field_type'], array_merge($options['field_options'], array('label' => $name, 'required' => $locale == $this->translationsHelper->getDefaultLocale() ? $options['required'] : false)));
     }
     $transformer = new TranslationFieldDataTransformer();
     $transformer->setCultures(array_keys($this->translationsHelper->getLanguages()))->setField($builder->getName())->setDefaultCulture($this->translatableListener->getDefaultLocale());
     // Adds transformer
     $builder->addModelTransformer($transformer);
     // On PreSet data - build translations
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($transformer) {
         $form = $event->getForm();
         $parentForm = $form->getParent();
         if ($parentForm->getData()) {
             $transformer->setObject($parentForm->getData());
         }
     }, -10);
     // On PostSet data - persist translations
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($transformer) {
         foreach ($transformer->getFieldTranslations() as $translation) {
             $this->entityManager->persist($translation);
         }
     }, -10);
 }
示例#24
0
 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $options['tag'] = $builder->getName();
 }
示例#25
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add($builder->getName(), 'date', $options);
 }
 /**
  * @param \Symfony\Component\Form\FormBuilderInterface $builder
  * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
  */
 private function getFileEventDispatcher(FormBuilderInterface $builder)
 {
     return $builder->get($builder->getName())->getEventDispatcher();
 }
 /**
  * Builds the form.
  *
  * @param \Sonata\AdminBundle\Util\AdminObjectAclData  $data
  * @param \Symfony\Component\Form\FormBuilderInterface $formBuilder
  * @param \Traversable                                 $aclValues
  *
  * @return \Symfony\Component\Form\Form
  */
 protected function buildForm(AdminObjectAclData $data, FormBuilderInterface $formBuilder, \Traversable $aclValues)
 {
     // Retrieve object identity
     $objectIdentity = ObjectIdentity::fromDomainObject($data->getObject());
     $acl = $data->getSecurityHandler()->getObjectAcl($objectIdentity);
     if (!$acl) {
         $acl = $data->getSecurityHandler()->createAcl($objectIdentity);
     }
     $data->setAcl($acl);
     $masks = $data->getMasks();
     $securityInformation = $data->getSecurityInformation();
     foreach ($aclValues as $key => $aclValue) {
         $securityIdentity = $this->getSecurityIdentity($aclValue);
         $permissions = array();
         foreach ($data->getUserPermissions() as $permission) {
             try {
                 $checked = $acl->isGranted(array($masks[$permission]), array($securityIdentity));
             } catch (NoAceFoundException $e) {
                 $checked = false;
             }
             $attr = array();
             if (self::ACL_ROLES_FORM_NAME === $formBuilder->getName() && isset($securityInformation[$aclValue]) && array_search($permission, $securityInformation[$aclValue]) !== false) {
                 $attr['disabled'] = 'disabled';
             }
             $permissions[$permission] = array('required' => false, 'data' => $checked, 'disabled' => array_key_exists('disabled', $attr), 'attr' => $attr);
         }
         $formBuilder->add($key, new AclMatrixType(), array('permissions' => $permissions, 'acl_value' => $aclValue));
     }
     return $formBuilder->getForm();
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->setAttribute('filter_options', array('reference_type' => $options['reference_type'], 'reference_name' => null !== $options['reference_name'] ? $options['reference_name'] : ucfirst($builder->getName())));
 }
 /**
  * @param \Symfony\Component\Form\FormBuilderInterface $formBuilder
  * @param bool                                         $prefix
  */
 public function __construct(FormBuilderInterface $formBuilder, $prefix = false)
 {
     $this->formBuilder = $formBuilder;
     $this->prefix = $prefix ? $prefix : $formBuilder->getName();
     $this->iterator = new \ArrayIterator(self::getKeys($formBuilder));
 }
示例#30
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('att', HiddenType::class, ['empty_data' => $builder->getName()]);
 }