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


PHP FormBuilderInterface::addEventListener方法代码示例

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


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

示例1: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     // You could tag the permission managers and then get them
     // here instead of hard coding ...
     $builder->add('permissionType', 'choice', array('choices' => array('admin' => 'sonata admins', 'object' => 'objects', 'route' => 'routes'), 'label' => 'Permission Type'));
     $builder->add('identity', 'tsk_identity_dropdown');
     $builder->add('identityType', 'hidden');
     $factory = $builder->getFormFactory();
     // We use a closure to populate permissions and masks for user
     $refreshPerms = function ($form, $perms) use($factory) {
         $form->add($factory->createNamed('permissions', 'collection', $perms, array('type' => 'tsk_permission_type', 'options' => array('label_attr' => array('class' => 'perm-collection')))));
     };
     //
     // Use FormEvents to add the permissions array dynamically
     //
     $builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($factory, $refreshPerms) {
         $form = $event->getForm();
         $data = $event->getData();
         if (!empty($data['identity'])) {
             $perms = $this->permissionsManager->getPermissionsForIdentity($data['identity'], $data['identityType']);
             $refreshPerms($form, $perms);
         }
     });
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory, $refreshPerms) {
         $form = $event->getForm();
         $data = $event->getData();
         if ($data->getIdentity()) {
             $perms = $this->permissionsManager->getPermissionsForIdentity($data->getIdentity(), $data->getIdentityType());
             $refreshPerms($form, $perms);
         }
     });
 }
开发者ID:sgh1986915,项目名称:symfony-tsk,代码行数:32,代码来源:PermissionSetType.php

示例2: buildForm

 /**
  * define form fields.
  *
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $viewToIdTransformer = new ViewToIdTransformer($this->entityManager);
     $builder->add('name', null, ['label' => 'form.article.name.label'])->add('description', null, ['label' => 'form.article.description.label', 'required' => false])->add('image', 'media', ['required' => false, 'label' => 'form.article.image.label'])->add($builder->create('blog', 'hidden', ['label' => 'form.article.blog.label'])->addModelTransformer($viewToIdTransformer))->add('template')->add('tags', 'tags', ['required' => false, 'multiple' => true])->remove('visibleOnFront');
     $builder->get('blog')->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $data = $event->getData();
         $parent = $event->getForm()->getParent();
         $this->manageCategories($data, $parent);
         $this->manageTemplate($data, $parent);
     });
     $builder->get('blog')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         $data = $event->getData();
         $parent = $event->getForm()->getParent();
         $this->manageCategories($data, $parent);
     });
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $data = $event->getData();
         $form = $event->getForm();
         $this->manageTags($data, $form);
     });
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         $form = $event->getForm();
         $data = $form->getData();
         $this->manageTags($data, $form);
     });
 }
开发者ID:global01,项目名称:victoire,代码行数:32,代码来源:ArticleType.php

示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('page_url', 'text', ['label' => 'mautic.page.point.action.form.page.url', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.page.point.action.form.page.url.descr', 'placeholder' => 'http://']]);
     // $default = (isset($options['data']) && isset($options['data']['first_time'])) ? $options['data']['first_time'] : false;
     // $builder->add('first_time', 'yesno_button_group', array(
     //     'label'       => 'mautic.page.point.action.form.first.time.only',
     //     'attr'        => array(
     //         'tooltip' => 'mautic.page.point.action.form.first.time.only.descr'
     //     ),
     //     'data'        => $default
     // ));
     $builder->add('page_hits', 'integer', ['label' => 'mautic.page.hits', 'label_attr' => ['class' => 'control-label'], 'required' => false, 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.page.point.action.form.page.hits.descr']]);
     $formModifier = function (FormInterface $form, $data) use($builder) {
         $unit = isset($data['accumulative_time_unit']) ? $data['accumulative_time_unit'] : 'H';
         $form->add('accumulative_time_unit', 'hidden', ['data' => $unit]);
         $secondsTransformer = new SecondsConversionTransformer($unit);
         $form->add($builder->create('accumulative_time', 'text', ['label' => 'mautic.page.point.action.form.accumulative.time', 'required' => false, 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.page.point.action.form.accumulative.time.descr'], 'auto_initialize' => false])->addViewTransformer($secondsTransformer)->getForm());
         $unit = isset($data['returns_within_unit']) ? $data['returns_within_unit'] : 'H';
         $secondsTransformer = new SecondsConversionTransformer($unit);
         $form->add('returns_within_unit', 'hidden', ['data' => $unit]);
         $form->add($builder->create('returns_within', 'text', ['label' => 'mautic.page.point.action.form.returns.within', 'required' => false, 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.page.point.action.form.returns.within.descr', 'onBlur' => 'Mautic.EnablesOption(this.id)'], 'auto_initialize' => false])->addViewTransformer($secondsTransformer)->getForm());
         $unit = isset($data['returns_after_unit']) ? $data['returns_after_unit'] : 'H';
         $secondsTransformer = new SecondsConversionTransformer($unit);
         $form->add('returns_after_unit', 'hidden', ['data' => $unit]);
         $form->add($builder->create('returns_after', 'text', ['label' => 'mautic.page.point.action.form.returns.after', 'required' => false, 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.page.point.action.form.returns.after.descr', 'onBlur' => 'Mautic.EnablesOption(this.id)'], 'auto_initialize' => false])->addViewTransformer($secondsTransformer)->getForm());
     };
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) {
         $data = $event->getData();
         $formModifier($event->getForm(), $data);
     });
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($formModifier) {
         $data = $event->getData();
         $formModifier($event->getForm(), $data);
     });
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:38,代码来源:PointActionUrlHitType.php

示例4: buildDeleteField

 protected function buildDeleteField(FormBuilderInterface $builder, array $options)
 {
     // add delete only if there is a file
     $storage = $this->storage;
     $translator = $this->translator;
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($options, $storage, $translator) {
         $form = $event->getForm();
         $object = $form->getParent()->getData();
         // no object or no uploaded file: no delete button
         if (null === $object || null === $storage->resolveUri($object, $form->getName())) {
             return;
         }
         $form->add('delete', $this->getFieldType('checkbox'), array('label' => $translator->trans('form.label.delete', array(), 'VichUploaderBundle'), 'required' => false, 'mapped' => false));
     });
     // delete file if needed
     $handler = $this->handler;
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($handler) {
         $delete = $event->getForm()->has('delete') ? $event->getForm()->get('delete')->getData() : false;
         $entity = $event->getForm()->getParent()->getData();
         if (!$delete) {
             return;
         }
         $handler->remove($entity, $event->getForm()->getName());
     });
 }
开发者ID:j0ssGZ,项目名称:VichUploaderBundle,代码行数:25,代码来源:VichFileType.php

示例5: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $employee = $event->getData();
         $form = $event->getForm();
         if ($employee && $employee->getId() === NULL && $this->boundlessAccess || $employee && $employee->getId() !== NULL && $this->boundedAccess) {
             $form->add('username', 'text', ['label' => 'employee.username.label', 'attr' => ['placeholder' => 'employee.username.placeholder']]);
         }
     });
     $builder->add('name', 'text', ['required' => FALSE, 'label' => 'employee.name.label', 'attr' => ['placeholder' => 'employee.name.placeholder']])->add('surname', 'text', ['required' => FALSE, 'label' => 'employee.surname.label', 'attr' => ['placeholder' => 'employee.surname.placeholder']])->add('patronymic', 'text', ['required' => FALSE, 'label' => 'employee.patronymic.label', 'attr' => ['placeholder' => 'employee.patronymic.placeholder']])->add('email', 'email', ['required' => FALSE, 'label' => 'employee.email.label', 'attr' => ['placeholder' => 'employee.email.placeholder']])->add('phoneNumber', 'text', ['required' => FALSE, 'label' => 'employee.phone_number.label', 'attr' => ['placeholder' => 'employee.phone_number.placeholder']])->add('skypeName', 'text', ['required' => FALSE, 'label' => 'employee.skype_name.label', 'attr' => ['placeholder' => 'employee.skype_name.placeholder']]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $employee = $event->getData();
         $form = $event->getForm();
         if ($employee && $employee->getId() !== NULL) {
             $form->add('employeeGroup', 'text', ['required' => FALSE, 'read_only' => TRUE, 'disabled' => TRUE, 'data_class' => 'AppBundle\\Entity\\Employee\\EmployeeGroup', 'label' => 'employee.employee_group.label'])->add('password', 'repeated', ['required' => FALSE, 'first_name' => "password", 'second_name' => "password_confirm", 'type' => "password", 'first_options' => ['label' => 'employee.password.label', 'attr' => ['placeholder' => 'employee.password.placeholder']], 'second_options' => ['label' => 'employee.password_confirm.label', 'attr' => ['placeholder' => 'employee.password_confirm.placeholder']]]);
             if ($this->boundedAccess) {
                 $form->add('isEnabled', 'checkbox', ['required' => FALSE, 'label' => 'employee.is_enabled.label']);
             }
             $form->add('update', 'submit', ['label' => 'common.update.label']);
             if ($this->boundlessAccess) {
                 $form->add('update_and_return', 'submit', ['label' => 'common.update_and_return.label']);
             }
         } else {
             $form->add('employeeGroup', 'entity', ['class' => "AppBundle\\Entity\\Employee\\EmployeeGroup", 'empty_data' => 0, 'choice_label' => "name", 'label' => 'employee.employee_group.label', 'empty_value' => 'common.choice.placeholder', 'invalid_message' => $this->_translator->trans('employee.employee_group.invalid_massage', [], 'validators'), 'query_builder' => function (EmployeeGroupRepository $repository) {
                 return $repository->getSubordinateRolesQuery($this->boundlessAccess);
             }])->add('password', 'repeated', ['required' => TRUE, 'first_name' => "password", 'second_name' => "password_confirm", 'type' => "password", 'first_options' => ['label' => 'employee.password.label', 'attr' => ['data-rule-required' => "true", 'data-msg-required' => $this->_translator->trans('employee.password.not_blank', [], 'validators'), 'placeholder' => 'employee.password.placeholder']], 'second_options' => ['label' => 'employee.password_confirm.label', 'attr' => ['data-rule-required' => "true", 'data-msg-required' => $this->_translator->trans('employee.password_confirm.not_blank', [], 'validators'), 'placeholder' => 'employee.password_confirm.placeholder']]])->add('create', 'submit', ['label' => 'common.create.label']);
             if ($this->boundlessAccess) {
                 $form->add('create_and_return', 'submit', ['label' => 'common.create_and_return.label']);
             }
         }
     });
 }
开发者ID:Kid-Binary,项目名称:Boilerplate,代码行数:32,代码来源:EmployeeType.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $steam = $builder->getData();
     $builder->add('name', 'text', ['label' => 'game.name'])->add('machine', 'dedipanel_machine_entity')->add('dir', 'text', ['label' => 'game.dir'])->add('port', 'integer', ['label' => 'game.port'])->add('game', 'entity', ['label' => 'game.selectGame', 'class' => 'DPGameBundle:Game', 'query_builder' => function (GameRepository $repo) {
         return $repo->getQBAvailableSteamGames();
     }])->add('mode', 'choice', ['choices' => SteamServer::getModeList(), 'empty_value' => 'steam.chooseGameMode', 'label' => 'steam.gameMode', 'required' => false])->add('maxplayers', 'integer', ['label' => 'game.maxplayers'])->add('rconPassword', 'text', ['label' => 'game.rcon.password'])->add('svPassword', 'text', ['label' => 'steam.svPassword', 'required' => false])->add('core', 'dedipanel_core_assignment', ['machine' => $steam->getMachine()])->add('alreadyInstalled', 'dictionary', ['name' => 'yes_no', 'label' => 'game.isAlreadyInstalled', 'expanded' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var \Symfony\Component\Form\FormInterface $form */
         $form = $event->getForm();
         /** @var \DP\GameServer\SteamServerBundle\Entity\SteamServer $steam */
         $steam = $event->getData();
         if ($steam->getId() != null && $steam->getInstallationStatus() > 100) {
             $form->add('rebootAt', 'time', ['label' => 'steam.rebootAt', 'required' => false]);
         }
     });
     $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
         /** @var \Symfony\Component\Form\FormInterface $form */
         $form = $event->getForm();
         /** @var \DP\GameServer\SteamServerBundle\Entity\SteamServer $steam */
         $steam = $event->getData();
         if ($steam->getGame() !== null && $steam->getGame()->getAppId() == 740) {
             // == csgo
             $form->add('mode', 'choice', ['choices' => SteamServer::getModeList(), 'label' => 'steam.gameMode', 'empty_value' => 'steam.chooseGameMode']);
         } elseif ($steam->getGame() !== null) {
             $form->remove('mode');
         }
     });
 }
开发者ID:Onneil,项目名称:dedipanel,代码行数:31,代码来源:SteamServerType.php

示例7: buildForm

 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('folders', 'collection', ['required' => false, 'allow_add' => true, 'type' => 'oro_email_email_folder_api', 'error_bubbling' => false])->add('from', 'oro_email_email_address_api', ['required' => false])->add('to', 'oro_email_email_address_api', ['required' => false, 'multiple' => true])->add('cc', 'oro_email_email_address_api', ['required' => false, 'multiple' => true])->add('bcc', 'oro_email_email_address_api', ['required' => false, 'multiple' => true])->add('subject', 'text', ['required' => false, 'constraints' => [new Assert\Length(['max' => 500])]])->add('body', 'text', ['required' => false])->add('bodyType', 'hidden', ['required' => false, 'data_transformer' => 'oro_email.email_body_type_transformer'])->add('createdAt', 'oro_datetime', ['required' => false])->add('sentAt', 'oro_datetime', ['required' => false])->add('receivedAt', 'oro_datetime', ['required' => false])->add('internalDate', 'oro_datetime', ['required' => false])->add('importance', 'hidden', ['required' => false, 'data_transformer' => 'oro_email.email_importance_transformer'])->add('head', 'choice', ['required' => false, 'choices' => [0 => false, 1 => true]])->add('seen', 'choice', ['required' => false, 'choices' => [0 => false, 1 => true]])->add('messageId', 'text', ['required' => false, 'constraints' => [new Assert\Length(['max' => 255])]])->add('xMessageId', 'text', ['required' => false, 'constraints' => [new Assert\Length(['max' => 255])]])->add('xThreadId', 'text', ['required' => false, 'constraints' => [new Assert\Length(['max' => 255])]])->add('thread', 'oro_entity_identifier', ['required' => false, 'class' => 'OroEmailBundle:EmailThread', 'multiple' => false, 'error_bubbling' => false])->add('refs', 'text', ['required' => false]);
     $builder->addEventSubscriber(new PatchSubscriber());
     $builder->addEventListener(FormEvents::POST_SET_DATA, [$this, 'postSetData']);
     $builder->addEventListener(FormEvents::POST_SUBMIT, [$this, 'postSubmit']);
 }
开发者ID:Maksold,项目名称:platform,代码行数:12,代码来源:EmailApiType.php

示例8: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('entityName', 'hidden', ['attr' => ['data-default-value' => Email::ENTITY_CLASS], 'constraints' => [new Assert\Choice(['choices' => ['', Email::ENTITY_CLASS]])]])->add('type', 'choice', ['label' => 'oro.email.emailtemplate.type.label', 'multiple' => false, 'expanded' => true, 'choices' => ['html' => 'oro.email.datagrid.emailtemplate.filter.type.html', 'txt' => 'oro.email.datagrid.emailtemplate.filter.type.txt'], 'required' => true])->add('translations', 'oro_email_emailtemplate_translatation', ['label' => 'oro.email.emailtemplate.translations.label', 'locales' => $this->getLanguages(), 'labels' => $this->getLocaleLabels(), 'content_options' => ['constraints' => [new Assert\NotBlank()], 'attr' => ['data-default-value' => $this->cm->get('oro_email.signature', '')]], 'subject_options' => ['constraints' => [new Assert\NotBlank()]]])->add('visible', 'checkbox', ['label' => 'oro.email.autoresponserule.form.template.visible.label', 'required' => false]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $form = $event->getForm();
         if ($form->has('owner')) {
             $form->remove('owner');
         }
         if (!$event->getData()) {
             $emailTemplate = new EmailTemplate();
             $emailTemplate->setContent($this->cm->get('oro_email.signature', ''));
             $emailTemplate->setEntityName(Email::ENTITY_CLASS);
             $event->setData($emailTemplate);
         }
     });
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
         $template = $event->getData();
         if (!$template || $template->getName()) {
             return;
         }
         $proposedName = $template->getSubject();
         while ($this->templateExists($proposedName)) {
             $proposedName .= rand(0, 10);
         }
         $template->setName($proposedName);
     });
 }
开发者ID:Maksold,项目名称:platform,代码行数:30,代码来源:AutoResponseTemplateType.php

示例9: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('security', new FundFormType());
     if ($this->account) {
         $builder->add('account_id', 'hidden', array('data' => $this->account->getId(), 'property_path' => false));
     }
     $em = $this->em;
     $ria = $this->account->getClient()->getProfile()->getRia();
     $builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) use($em, $ria) {
         $form = $event->getForm();
         $data = $event->getData();
         $existSecurity = $em->getRepository('WealthbotAdminBundle:Security')->findOneBy(array('name' => $data['security']['name'], 'symbol' => $data['security']['symbol']));
         if ($existSecurity) {
             $form->get('security')->setData($existSecurity);
             $existSecurityAssignment = $em->getRepository('WealthbotAdminBundle:SecurityAssignment')->findOneBy(array('ria_user_id' => $ria->getId(), 'security_id' => $existSecurity->getId()));
             if ($existSecurityAssignment) {
                 $form->setData($existSecurityAssignment);
             }
         }
     });
     $builder->addEventListener(FormEvents::BIND, function (FormEvent $event) use($ria) {
         $data = $event->getData();
         if ($data) {
             //                $data->setRia($ria); Deprecated
         }
     });
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:27,代码来源:OutsideFundFormType.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if ($options['autocomplete']) {
         $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'preSetData']);
         $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'preSubmit']);
     }
 }
开发者ID:ynloultratech,项目名称:framework,代码行数:10,代码来源:Select2AutocompleteExtension.php

示例11: buildForm

 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);
     });
 }
开发者ID:benedicthelfer,项目名称:translatable-form-field,代码行数:26,代码来源:TranslatorType.php

示例12: buildForm

 /**
  * @param FormBuilderInterface $builder
  * @param array $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $originalRecipients = new ArrayCollection();
     $builder->add('originator', 'text', ['disabled' => true, 'mapped' => false, 'data' => $this->currentUser->getFullname()])->add('recipients', 'collection', ['type' => 'azhuravlov_sa_recipient', 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false])->add('subject')->add('priority', 'choice', ['choices' => Approval::getPriorities()])->add('body', 'textarea', ['attr' => array('style' => 'height: 500px;')])->add('submit', 'submit', ['attr' => array('class' => 'btn btn-success btn-lg')]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var Approval $data */
         $data = $event->getData();
         $data->setOriginator($this->currentUser);
     });
     // Recipients before
     $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use(&$originalRecipients) {
         /** @var Approval $entity */
         $entity = $event->getData();
         foreach ($entity->getRecipients() as $recipient) {
             $originalRecipients->add($recipient);
         }
     });
     // Recipients after
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use(&$originalRecipients) {
         /** @var Approval $entity */
         $entity = $event->getData();
         foreach ($originalRecipients as $recipient) {
             if (false === $entity->getRecipients()->contains($recipient)) {
                 $entity->getRecipients()->removeElement($recipient);
             }
         }
     });
 }
开发者ID:azhuravlov,项目名称:SingleApproval,代码行数:32,代码来源:ApprovalType.php

示例13: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('metatag', 'checkbox', array('required' => false))->add('display', 'checkbox', array('required' => false))->add('cod', 'text', array('attr' => array('pattern' => "^\\w*\$", 'oninvalid' => "setCustomValidity('The code can not have blank spaces neither special characters')", 'oninput' => "setCustomValidity('')"), 'label' => $this->translator->trans('Cod', array(), null, $this->locale)))->add('i18n_title', 'texti18n', array('label' => $this->translator->trans('Title', array(), null, $this->locale)))->add('i18n_description', 'textareai18n', array('required' => false, 'label' => $this->translator->trans('Description', array(), null, $this->locale)));
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $tag = $event->getData();
         $fields = $tag->getProperty("customfield");
         foreach (array_filter(preg_split('/[,\\s]+/', $fields)) as $field) {
             $auxField = explode(":", $field);
             $formOptions = array('mapped' => false, 'required' => false, 'data' => $tag->getProperty($auxField[0]));
             try {
                 $event->getForm()->add($auxField[0], isset($auxField[1]) ? $auxField[1] : 'text', $formOptions);
             } catch (\InvalidArgumentException $e) {
                 $event->getForm()->add($auxField[0], 'text', $formOptions);
             }
         }
     });
     $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
         $tag = $event->getData();
         $fields = $tag->getProperty("customfield");
         foreach (array_filter(preg_split('/[,\\s]+/', $fields)) as $field) {
             $auxField = explode(":", $field);
             $data = $event->getForm()->get($auxField[0])->getData();
             $tag->setProperty($auxField[0], $data);
         }
     });
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:26,代码来源:TagType.php

示例14: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('prices', ProductPriceCollectionType::NAME, ['label' => 'orob2b.pricing.productprice.entity_plural_label', 'required' => false, 'mapped' => false, 'constraints' => [new UniqueProductPrices()]]);
     $builder->addEventListener(FormEvents::POST_SET_DATA, [$this, 'onPostSetData']);
     $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
     $builder->addEventListener(FormEvents::POST_SUBMIT, [$this, 'onPostSubmit'], 10);
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:10,代码来源:ProductFormExtension.php

示例15: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('institution', 'entity', array('class' => 'App\\ResumeBundle\\Entity\\Institution', 'label' => false, 'required' => true, 'attr' => array('class' => 'institution-select'), 'widget_form_group' => false, 'horizontal_input_wrapper_class' => "col-sm-6 col-xs-12 institution-wrapper"))->add('otherInstitution', 'text', array('label' => false, 'required' => true, 'attr' => array('placeholder' => 'Institution name'), 'widget_form_group' => false, 'horizontal_input_wrapper_class' => 'other-institution-wrapper col-sm-6 col-xs-12 hidden', 'constraints' => array(new Length(array('max' => 100)))))->add('degree', null, array('label' => false, 'widget_form_group' => false, 'horizontal_input_wrapper_class' => "col-sm-6 col-xs-12 pull-right", 'constraints' => array(new Length(array('max' => 100)), new NotBlank()), 'attr' => array('placeholder' => 'Degree (e.g. Bachelor of Commerce) ', 'maxlength' => false)));
     // If institution is empty remove that field
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $ev) {
         $edu = $ev->getData();
         if ($edu === null) {
             return;
         }
         if ($edu->getInstitution() === null) {
             $ev->getForm()->remove('institution');
         }
     });
     // Remove institution if other institution has an error or has a value
     $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
         $edu = $event->getData();
         if (!$edu->getInstitution() && !$edu->getOtherInstitution()) {
             $event->getForm()->remove('institution');
             $event->getForm()->get('otherInstitution')->addError(new FormError("Institution name is required"));
         }
         if (!$edu->getInstitution() && $edu->getOtherInstitution()) {
             $event->getForm()->remove('institution');
         }
     });
 }
开发者ID:hoangnd25,项目名称:IndustryProject,代码行数:25,代码来源:EducationType.php


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