/** * 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); }); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('title', 'text', array('label' => 'Title', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus'))); $builder->add('slug', 'text', array('label' => 'Address', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED)); $myExtraFieldValidator = function (FormEvent $event) { global $CONFIG; $form = $event->getForm(); $myExtraField = $form->get('slug')->getData(); if (!ctype_alnum($myExtraField) || strlen($myExtraField) < 2) { $form['slug']->addError(new FormError("Numbers and letters only, at least 2.")); } else { if (in_array($myExtraField, $CONFIG->siteSlugReserved)) { $form['slug']->addError(new FormError("That is already taken.")); // The above checks provide a nice error message. // Now let's do a final belt and braces check. } else { if (!SiteModel::isSlugValid($myExtraField, $CONFIG)) { $form['slug']->addError(new FormError("That is not allowed.")); } } } }; $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator); $readChoices = array('public' => 'Public, and listed on search engines and our directory', 'protected' => 'Public, but not listed so only people who know about it can find it'); $builder->add('read', 'choice', array('label' => 'Who can read?', 'required' => true, 'choices' => $readChoices, 'expanded' => true)); $builder->get('read')->setData('public'); $writeChoices = array('public' => 'Anyone can add data', 'protected' => 'Only people I say can add data'); $builder->add('write', 'choice', array('label' => 'Who can write?', 'required' => true, 'choices' => $writeChoices, 'expanded' => true)); $builder->get('write')->setData('public'); }
public function buildForm(FormBuilderInterface $builder, array $options) { global $allFilingPlaces; // extremer Dirty Hack, aber nichts anderes hat funktioniert... $builder->add('title', null, array('label' => 'Titel:'))->add('path', TextType::class, array('label' => 'Pfad:'))->add('docDate', TextType::class, array('label' => 'Datum:'))->add('tags', null, array('label' => 'Stichworte:'))->add('filingPlace', ChoiceType::class, array('label' => 'Physischer Ablageort:', 'choices' => $allFilingPlaces))->add('notes', null, array('label' => 'Bemerkungen:'))->add('reminderText', null, array('label' => 'Text:'))->add('reminderDueDate', TextType::class, array('label' => 'Fälligkeitsdatum:'))->add('reminderStatus', ChoiceType::class, array('label' => 'Status:', 'choices' => ['offen' => 'offen', 'erledigt' => 'erledigt']))->add('save', SubmitType::class, ['label' => 'Speichern']); $builder->get('filingPlace')->resetViewTransformers(); $builder->get('docDate')->addModelTransformer(new CallbackTransformer(function ($datetime) { // Umwandlung aus DB in Formular return $datetime instanceof \DateTime ? $datetime->format('d.m.Y') : ''; }, function ($germandate) { // Umwandlung aus Formular in DB-Format $d = new \Datetime($germandate); return $d; })); $builder->get('reminderDueDate')->addModelTransformer(new CallbackTransformer(function ($datetime) { // Umwandlung aus DB in Formular return $datetime instanceof \DateTime ? $datetime->format('d.m.Y') : ''; }, function ($germandate) { // Umwandlung aus Formular in DB-Format if (strlen($germandate) > 0) { $d = new \Datetime($germandate); return $d; } return null; })); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('country', 'entity', array('class' => 'GsmLotTraderBundle:Country', 'required' => false))->setMethod('get')->add('brand', 'entity', array('class' => 'GsmLotOfferBundle:Brand', 'empty_data' => null, 'empty_value' => '', 'required' => false))->setMethod('get')->add('norm', 'entity', array('class' => 'GsmLotOfferBundle:Norm', 'label' => 'Specification', 'required' => false)); $formUpdateBrand = function (FormInterface $form, $data) { $modelOptions = array('required' => false, 'class' => 'GsmLotOfferBundle:Model', 'empty_data' => null, 'empty_value' => '', 'query_builder' => function (EntityRepository $er) use($data) { return $er->createQueryBuilder('m')->where('m.brand = :brand_id')->setParameter('brand_id', $data)->orderBy('m.name', 'asc'); }); $form->add('model', 'entity', $modelOptions); }; $formUpdateCountry = function (FormInterface $form, $data) { $cityOptions = array('required' => false, 'class' => 'GsmLotTraderBundle:City', 'empty_data' => null, 'empty_value' => '', 'query_builder' => function (EntityRepository $er) use($data) { return $er->createQueryBuilder('c')->where('c.country = :country_id')->setParameter('country_id', $data)->orderBy('c.name', 'asc'); }); $form->add('city', 'entity', $cityOptions); }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formUpdateBrand, $formUpdateCountry) { $data = $event->getData(); $formUpdateBrand($event->getForm(), $data); $formUpdateCountry($event->getForm(), $data); }); $builder->get('brand')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formUpdateBrand) { $data = $event->getForm()->getData(); $formUpdateBrand($event->getForm()->getParent(), $data); }); $builder->get('country')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formUpdateCountry) { $data = $event->getForm()->getData(); $formUpdateCountry($event->getForm()->getParent(), $data); }); }
public function buildForm(FormBuilderInterface $builder, array $options) { $defaultRequired = true; $constraints = array(new NotBlank()); if ($this->patch) { $defaultRequired = false; $constraints = array(); } $builder->add('name', null, array('required' => $defaultRequired, 'constraints' => $constraints)); $builder->add('type', 'choice', array('choices' => array('integer' => 'integer', 'text' => 'text', 'textarea' => 'textarea', 'url' => 'url', 'boolean' => 'boolean'), 'required' => $defaultRequired, 'constraints' => $constraints)); $builder->add('scope', 'choice', array('choices' => array('frontend' => 'frontend', 'backend' => 'backend'), 'required' => $defaultRequired, 'constraints' => $constraints)); $builder->add('required', 'checkbox', array('required' => $defaultRequired, 'constraints' => $constraints)); $callback = function (FormEvent $event) { if (null === $event->getData()) { // check if the Form's field is empty if (is_bool($event->getForm()->getData())) { // check if it's a boolean if ($event->getForm()->getData()) { $event->setData('1'); } else { $event->setData('0'); } } else { // set the data back $event->setData($event->getForm()->getData()); } } }; $builder->get('name')->addEventListener(FormEvents::PRE_SUBMIT, $callback); $builder->get('type')->addEventListener(FormEvents::PRE_SUBMIT, $callback); $builder->get('scope')->addEventListener(FormEvents::PRE_SUBMIT, $callback); $builder->get('required')->addEventListener(FormEvents::PRE_SUBMIT, $callback); }
public function buildForm(FormBuilderInterface $builder, array $options) { $defaultRequired = true; $constraints = array(new NotBlank()); if ($this->patch) { $defaultRequired = false; $constraints = array(); } $builder->add('fields', 'collection', array('type' => new SnippetFieldType(array('patch' => $this->patch)), 'required' => $defaultRequired, 'constraints' => $constraints)); $builder->add('name', null, array('required' => $defaultRequired, 'constraints' => $constraints)); $builder->add('enabled', 'checkbox', array('required' => false)); $callback = function (FormEvent $event) { if (null === $event->getData()) { // check if the Form's field is empty if (is_bool($event->getForm()->getData())) { // check if it's a boolean if ($event->getForm()->getData()) { $event->setData('1'); } else { $event->setData('0'); } } else { // set the data back $event->setData($event->getForm()->getData()); } } }; $builder->get('name')->addEventListener(FormEvents::PRE_SUBMIT, $callback); $builder->get('enabled')->addEventListener(FormEvents::PRE_SUBMIT, $callback); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('language', ChoiceType::class, ['choices' => Configuration::LANGUAGES])->add('envVars', null, ['required' => false])->add('preparationScript', null, ['required' => false])->add('launchScript', null, ['required' => false])->add('vcs', ChoiceType::class, ['choices' => Configuration::VCS, 'required' => 'false']); $builder->get('envVars')->addModelTransformer(new ArrayToJsonDataTransformer()); $builder->get('preparationScript')->addModelTransformer(new ArrayToJsonDataTransformer()); $builder->get('launchScript')->addModelTransformer(new ArrayToJsonDataTransformer()); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('type', 'choice', array('label' => 'I am a', 'choices' => array(User::ROLE_STUDENT => 'Student', User::ROLE_GS1_MEMBER => 'Member'), 'data' => 'student', 'attr' => array('class' => 'account_type')))->add('firstName', null, array('attr' => array('maxlength' => false), 'render_required_asterisk' => true))->add('lastName', null, array('attr' => array('maxlength' => false), 'render_required_asterisk' => true))->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle', 'render_required_asterisk' => true))->add('plainPassword', 'repeated', array('type' => 'password', 'options' => array('translation_domain' => 'FOSUserBundle'), 'first_options' => array('label' => 'form.password', 'render_required_asterisk' => true), 'second_options' => array('label' => 'form.password_confirmation', 'render_required_asterisk' => true), 'invalid_message' => 'fos_user.password.mismatch'))->add('toc', 'checkbox', array('mapped' => false, 'label' => 'I agree to <a id="toc" href="#">terms & conditions</a>', 'constraints' => array(new IsTrue(array('message' => 'You must agree to terms & conditions')))))->add('studentProfile', new StudentRegistrationType($this->entityManager), array('label' => false, 'widget_form_group' => false, 'widget_type' => 'inline')); $builder->get('email')->setAttribute('render_required_asterisk', true); $builder->get('plainPassword')->setAttribute('render_required_asterisk', true); $builder->remove('username'); $formModifier = function (FormInterface $form, $type = null) { if ($type === User::ROLE_GS1_MEMBER) { $form->add('memberProfile', new MemberProfileType(), array('label' => false, 'widget_form_group' => false, 'widget_type' => 'inline', 'constraints' => array(new Valid())))->remove("studentProfile"); } }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) { $data = $event->getData(); $formModifier($event->getForm(), $data !== null ? $data->getType() : null); }); $builder->get('type')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) { $type = $event->getForm()->getData(); $formModifier($event->getForm()->getParent(), $type); }); $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $form = $event->getForm(); if ($form->getErrors(true)->count() > 0) { $form->get('plainPassword')->get('first')->addError(new FormError('The form is invalid, you must re-enter your password')); } }); // $builder->get('activatedAccessCode') // ->addModelTransformer(new StudentAccessCodeTransformer($this->entityManager)); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('email', 'email', array('label' => 'Email Of Owner', 'required' => true)); // The rest of this is duplicated from index\forms\CreateForm $builder->add('title', 'text', array('label' => 'Title', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED)); $builder->add('slug', 'text', array('label' => 'Slug For Web Address', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED)); $myExtraFieldValidator = function (FormEvent $event) { global $CONFIG; $form = $event->getForm(); $myExtraField = $form->get('slug')->getData(); if (!ctype_alnum($myExtraField) || strlen($myExtraField) < 2) { $form['slug']->addError(new FormError("Numbers and letters only, at least 2.")); } else { if (in_array($myExtraField, $CONFIG->siteSlugReserved)) { $form['slug']->addError(new FormError("That is already taken.")); } } }; $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator); $readChoices = array('public' => 'Public, and listed on search engines and our directory', 'protected' => 'Public, but not listed so only people who know about it can find it'); $builder->add('read', 'choice', array('label' => 'Who can read?', 'required' => true, 'choices' => $readChoices, 'expanded' => true)); $builder->get('read')->setData('public'); $writeChoices = array('public' => 'Anyone can add data', 'protected' => 'Only people I say can add data'); $builder->add('write', 'choice', array('label' => 'Who can write?', 'required' => true, 'choices' => $writeChoices, 'expanded' => true)); $builder->get('write')->setData('public'); }
public function buildForm(FormBuilderInterface $builder, array $options) { $projects = $this->projectRepository->getFormChoices(); $first = key($projects); $builder->add('name', TextType::class, array('label' => 'Name'))->add('project', ChoiceType::class, array('label' => 'Project', 'choices' => $projects))->add('url', UrlType::class, array('label' => 'Export URL'))->add('encryptionKey', TextType::class, ['label' => 'Encryption key'])->add('active', BooleanType::class, ['label' => 'Active'])->add('notes', TextareaType::class, ['label' => 'Notes'])->add('save', SubmitType::class, array('label' => 'Save')); $builder->get('project')->addModelTransformer(new EntityTransformer($this->projectRepository)); $formModifier = function (FormInterface $form, Project $project = null) use($first) { if (null === $project && false !== $first) { $project = $this->projectRepository->getItem($first); } $statuses = null === $project ? [] : $this->areaStatusRepository->getFormChoices($project); $form->add('areaStatus', new ChoiceType(), ['label' => 'Area status', 'choices' => $statuses]); }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) { $data = $event->getData(); $formModifier($event->getForm(), $data->getProject()); if (!empty($data->getAreaStatus())) { $data->setAreaStatus($data->getAreaStatus()->getId()); } }); $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { $data = $event->getData(); if (!empty($data->getAreaStatus()) && null !== $data->getProject()) { $this->areaStatusRepository->setProject($data->getProject()); $data->setAreaStatus($this->areaStatusRepository->getItem($data->getAreaStatus())); } }); $builder->get('project')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) { $project = $event->getForm()->getData(); $formModifier($event->getForm()->getParent(), $project); }); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('general', 'form', array('virtual' => true))->add('contact', 'form', array('virtual' => true))->add('studies', 'form', array('virtual' => true)); $builder->get('general')->add('firstName', 'text', array('label' => 'user.field.firstname'))->add('lastName', 'text', array('label' => 'user.field.lastname')); $builder->get('contact')->add('email', 'email', array('label' => 'user.field.email', 'required' => false))->add('mobilePhone', 'number', array('label' => 'user.field.mobile_phone', 'required' => false))->add('address', 'text', array('label' => 'user.field.address', 'required' => false))->add('zipcode', 'number', array('label' => 'user.field.zipcode', 'required' => false))->add('city', 'text', array('label' => 'user.field.city', 'required' => false)); $builder->get('studies')->add('level', 'entity', array('label' => 'user.student.field.level', 'class' => 'Mathsup\\ExerciseBundle\\Entity\\Level', 'required' => false))->add('remark', 'textarea', array('label' => 'user.field.remark', 'required' => false)); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('firstname', 'text', ['label' => 'employee.label.firstname'])->add('lastname', 'text', ['label' => 'employee.label.lastname'])->add('job', 'datalist', ['suggestions' => $this->em->getRepository('AppBundle:Job')->findAll(), 'label' => 'employee.label.job'])->add('location', 'datalist', ['suggestions' => $this->em->getRepository('AppBundle:Location')->findAll(), 'label' => 'employee.label.location'])->add('birthdate', 'date', ['widget' => 'single_text', 'format' => 'dd-MM-yyyy', 'label' => 'employee.label.birthdate', 'attr' => ['class' => 'datepicker']])->add('joinedAt', 'date', ['widget' => 'single_text', 'format' => 'dd-MM-yyyy', 'label' => 'employee.label.joined', 'attr' => ['class' => 'datepicker']]); $builder->get('location')->resetViewTransformers(); $builder->get('location')->addModelTransformer(new LocationToTextTransformer($this->em)); $builder->get('job')->resetViewTransformers(); $builder->get('job')->addModelTransformer(new JobToTextTransformer($this->em)); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('avatar', 'sonata_media_type', ['label' => false, 'provider' => 'sonata.media.provider.image', 'context' => 'avatar', 'required' => false]); $builder->get('avatar')->add('unlink', 'hidden', ['mapped' => false, 'data' => false]); $builder->get('avatar')->add('binaryContent', 'file', ['label' => false]); UserFormBuilder::baseBuildForm($builder); $builder->add('birthday', 'date', ['label' => 'form.profile.date', 'translation_domain' => 'FOSUserBundle', 'widget' => 'single_text', 'input' => 'datetime', 'attr' => ['class' => 'datepicker']]); }
public function buildForm(FormBuilderInterface $builder, array $options) { $statusChoices = $options['statusRepository']->getFormChoices(); $milestoneChoices = $options['milestoneRepository']->getFormChoices('Area'); $builder->add('name', TextType::class, array('label' => 'Name'))->add('newStatus', ChoiceType::class, array('label' => 'New status', 'required' => true, 'choices' => $statusChoices))->add('prevStatus', ChoiceType::class, array('label' => 'Previous status', 'required' => true, 'choices' => $statusChoices))->add('milestoneMap', ChoiceType::class, array('label' => 'Required milestones', 'expanded' => true, 'multiple' => true, 'choices' => $milestoneChoices))->add('activationOrder', NumberType::class, array('label' => 'Activation order'))->add('save', SubmitType::class, array('label' => 'Save')); $builder->get('newStatus')->addModelTransformer(new EntityTransformer($options['statusRepository'])); $builder->get('prevStatus')->addModelTransformer(new EntityTransformer($options['statusRepository'])); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('description', TextareaType::class, array('label' => 'Constat :', 'required' => false, "attr" => array("class" => "form-control", "rows" => 10)))->add('duree', TextType::class, array('label' => 'Durée effective du passage* :', 'attr' => array('class' => 'input-timepicker')))->add('save', SubmitType::class, array('label' => 'Valider', "attr" => array("class" => "btn btn-success"))); $builder->add('produits', CollectionType::class, array('entry_type' => new ProduitPassageType($this->dm), 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true, 'label' => '')); $builder->add('nettoyages', ChoiceType::class, array('label' => 'Nettoyage : ', 'choices' => $this->getNettoyages(), 'expanded' => false, 'multiple' => true, 'required' => false, 'attr' => array("class" => "select2 select2-simple", "multiple" => "multiple", "data-tags" => "true"))); $builder->get('nettoyages')->resetViewTransformers(); $builder->add('applications', ChoiceType::class, array('label' => 'Respect des applications : ', 'choices' => $this->getApplications(), 'expanded' => false, 'multiple' => true, 'required' => false, 'attr' => array("class" => "select2 select2-simple", "multiple" => "multiple"))); $builder->get('applications')->resetViewTransformers(); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('placeInstall', null, array('label' => 'rk_placeInstall', 'translation_domain' => 'address', 'attr' => array('class' => 'span3')))->add('keyNumber', null, array('label' => 'rk_keyNumber', 'translation_domain' => 'address', 'attr' => array('class' => 'span3')))->add('dateInstall', 'genemu_jquerydate', array('required' => false, 'label' => 'rk_dateInstall', 'translation_domain' => 'address', 'widget' => 'single_text', 'attr' => array('class' => 'span3'))); if (!$security->isGranted('ROLE_ADDRESSES_RACK_WRITE') and $security->isGranted('ROLE_ADDRESSES_RACK_READ')) { $builder->get('placeInstall')->setDisabled(true); $builder->get('keyNumber')->setDisabled(true); $builder->get('dateInstall')->setDisabled(true); } }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('id', HiddenType::class, ['required' => false, 'mapped' => false])->add('category', EntityType::class, ['class' => 'AppBundle\\Entity\\Asset\\Category', 'choice_label' => 'name', 'multiple' => false, 'expanded' => false, 'required' => true, 'label' => 'asset.category', 'preferred_choices' => function ($category, $key, $index) { return $category->isActive(); }, 'choice_translation_domain' => false])->add('name', TextType::class, ['label' => false, 'required' => true])->add('container', CheckboxType::class, ['label' => 'asset.container'])->add('comment', TextType::class, ['label' => false, 'required' => false])->add('active', CheckboxType::class, ['label' => 'common.active'])->add('requires', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true])->add('required_by', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true, 'property_path' => 'requiredBy'])->add('extends', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true])->add('extended_by', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true, 'property_path' => 'extendedBy']); $builder->get('requires')->addModelTransformer(new ModelRelationshipsToIdsTransformer($this->em)); $builder->get('required_by')->addModelTransformer(new ModelRelationshipsToIdsTransformer($this->em)); $builder->get('extends')->addModelTransformer(new ModelRelationshipsToIdsTransformer($this->em)); $builder->get('extended_by')->addModelTransformer(new ModelRelationshipsToIdsTransformer($this->em)); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $dateOptions = $builder->get('date')->getOptions(); $timeOptions = $builder->get('time')->getOptions(); $builder->remove('date')->add('date', 'datepicker', $dateOptions); if (isset($options['preferred_choices'])) { $timeOptions = array_merge($timeOptions, array('hours' => $options['preferred_choices']['hours'], 'minutes' => $options['preferred_choices']['minutes'])); $builder->remove('time')->add('time', 'time', $timeOptions); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $is_new = $builder->getData()->getId() ? false : true; $builder->add('nameUa', null, array('label' => 'c_nameUa', 'translation_domain' => 'address', 'attr' => array('class' => 'span4'))); $builder->add('nameRu', null, array('label' => 'c_nameRu', 'translation_domain' => 'address', 'attr' => array('class' => 'span4')))->add('prefixRu', null, array('label' => 'c_prefixRu', 'translation_domain' => 'address', 'attr' => array('class' => 'span2')))->add('prefixUa', null, array('label' => 'c_prefixUa', 'translation_domain' => 'address', 'attr' => array('class' => 'span2'))); if (!$is_new) { $builder->get('nameUa')->setDisabled(true); $builder->get('nameRu')->setDisabled(true); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $security = $options['security']; if ($security->isGranted('ROLE_ADDRESSES_HOUSE_ADDRESS_READ')) { $builder->add('name', null, array('label' => 'h_name', 'translation_domain' => 'address', 'attr' => array('class' => 'span1')))->add('region', null, array('label' => 'r_nameUa', 'translation_domain' => 'address', 'attr' => array('class' => 'span3')))->add('houseType', null, array('label' => 'h_houseType', 'translation_domain' => 'address', 'attr' => array('class' => 'span3')))->add('subRegion', null, array('label' => 'sb_nameUa', 'translation_domain' => 'address', 'attr' => array('class' => 'span3')))->add('street', null, array('label' => 's_nameUa', 'translation_domain' => 'address', 'attr' => array('class' => 'span3'))); } if ($security->isGranted('ROLE_ADDRESSES_HOUSE_PAY_PORT_READ')) { $builder->add('descr', 'textarea', array('required' => false, 'label' => 'h_descr', 'translation_domain' => 'address', 'attr' => array('class' => 'span10'))); } if ($security->isGranted('ROLE_ADDRESSES_HOUSE_ATTRIBUTE_READ')) { $builder->add('payPort', null, array('required' => false, 'label' => 'h_payPort', 'translation_domain' => 'address', 'attr' => array('class' => 'span1'))); } if ($security->isGranted('ROLE_ADDRESSES_HOUSE_OPTIKA_READ')) { $builder->add('optikaKan', null, array('required' => false, 'label' => 'h_optikaKan', 'translation_domain' => 'address', 'attr' => array('class' => 'span1'))); $builder->add('optikaAir', null, array('required' => false, 'label' => 'h_optikaAir', 'translation_domain' => 'address', 'attr' => array('class' => 'span1'))); } if (!$security->isGranted('ROLE_ADDRESSES_HOUSE_ADDRESS_WRITE') and $security->isGranted('ROLE_ADDRESSES_HOUSE_ADDRESS_READ')) { $builder->get('name')->setDisabled(true); $builder->get('region')->setDisabled(true); $builder->get('houseType')->setDisabled(true); $builder->get('subRegion')->setDisabled(true); $builder->get('street')->setDisabled(true); } if (!$security->isGranted('ROLE_ADDRESSES_HOUSE_PAY_PORT_WRITE') and $security->isGranted('ROLE_ADDRESSES_HOUSE_PAY_PORT_READ')) { $builder->get('payPort')->setDisabled(true); } if (!$security->isGranted('ROLE_ADDRESSES_HOUSE_ATTRIBUTE_WRITE') and $security->isGranted('ROLE_ADDRESSES_HOUSE_ATTRIBUTE_READ')) { $builder->get('descr')->setDisabled(true); } if (!$security->isGranted('ROLE_ADDRESSES_HOUSE_OPTIKA_WRITE') and $security->isGranted('ROLE_ADDRESSES_HOUSE_OPTIKA_READ')) { $builder->get('optikaAir')->setDisabled(true); $builder->get('optikaKan')->setDisabled(true); } }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('id', HiddenType::class, ['label' => false])->add('name', TextType::class, ['label' => false])->add('serial_number', TextType::class, ['label' => false])->add('model', TextType::class, ['label' => 'asset.model'])->add('status', EntityType::class, ['class' => 'AppBundle\\Entity\\Asset\\AssetStatus', 'choice_label' => 'name', 'multiple' => false, 'expanded' => false, 'required' => true, 'label' => 'asset.status', 'preferred_choices' => function ($status, $key, $index) { return $status->isActive(); }, 'choice_translation_domain' => false])->add('purchased', DateType::class, ['label' => 'common.purchased'])->add('cost', MoneyType::class, ['label' => 'common.cost', 'currency' => 'USD'])->add('value', MoneyType::class, ['label' => 'common.value', 'currency' => 'USD'])->add('location', AssetLocationType::class)->add('location_text', HiddenType::class)->add('comment', TextType::class, ['label' => false])->add('active', CheckboxType::class, ['label' => 'common.active'])->add('requires', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true])->add('required_by', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true, 'property_path' => 'requiredBy'])->add('extends', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true])->add('extended_by', CollectionType::class, ['entry_type' => EntityType::class, 'entry_options' => ['class' => 'AppBundle\\Entity\\Asset\\Model', 'choice_label' => false], 'by_reference' => false, 'required' => false, 'label' => false, 'empty_data' => null, 'allow_add' => true, 'allow_delete' => true, 'delete_empty' => true, 'property_path' => 'extendedBy']); $builder->get('requires')->addModelTransformer(new TrailerRelationshipsToIdsTransformer($this->em)); $builder->get('required_by')->addModelTransformer(new TrailerRelationshipsToIdsTransformer($this->em)); $builder->get('extends')->addModelTransformer(new TrailerRelationshipsToIdsTransformer($this->em)); $builder->get('extended_by')->addModelTransformer(new TrailerRelationshipsToIdsTransformer($this->em)); $builder->get('model')->addModelTransformer(new ModelToIdTransformer($this->em)); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('period', ChoiceType::class, array('choices' => array('spec_shaper_calendar.choice.days' => Reoccurance::FREQUENCY_DAY, 'spec_shaper_calendar.choice.weeks' => Reoccurance::FREQUENCY_WEEK, 'spec_shaper_calendar.choice.months' => Reoccurance::FREQUENCY_MONTH, 'spec_shaper_calendar.choice.years' => Reoccurance::FREQUENCY_YEAR), 'required' => false))->add('intervalBetween', IntegerType::class, array('label' => 'spec_shaper_calendarbundle.label.interval', 'attr' => array('min' => 1, 'max' => 30), 'required' => false))->add('stopMethod', ChoiceType::class, array('choices' => array('spec_shaper_calendar.choice.iterations' => Reoccurance::END_ITERATIONS, 'spec_shaper_calendar.choice.endDate' => Reoccurance::END_DATE), 'label' => false, 'required' => false))->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { $this->selectInitialFormView($event); }); $builder->get('period')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $this->periodChange($event); }); $builder->get('stopMethod')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $this->stopMethodChange($event); }); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('taps', 'hidden', array('required' => false))->add('garderies', 'hidden', array('required' => false)); $builder->get('taps')->addModelTransformer(new TapToStringTransformer($options['manager'], $builder->getData(), $options['days_of_week'])); $builder->get('garderies')->addModelTransformer(new GarderieToStringTransformer($options['manager'], $builder->getData(), $options['days_of_week'])); /** * @var \WCS\CantineBundle\Entity\Eleve $entity */ $entity = $builder->getData(); if (!$entity->isTapgarderieSigned()) { $builder->add('tapgarderie_atteste', 'checkbox', array('required' => true, 'mapped' => false))->add('tapgarderie_autorise', 'checkbox', array('required' => true, 'mapped' => false))->add('tapgarderie_certifie', 'checkbox', array('required' => true, 'mapped' => false)); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('name', TextType::class, array('label' => 'Name'))->add('territory', ChoiceType::class, array('label' => 'Territory', 'choices' => $options['territoryRepository']->getFormChoices()))->add('status', ChoiceType::class, array('label' => 'Status', 'choices' => $options['statusRepository']->getFormChoices()))->add('save', SubmitType::class, array('label' => 'Save')); $builder->get('territory')->addModelTransformer(new EntityTransformer($options['territoryRepository'])); $builder->get('status')->addModelTransformer(new EntityTransformer($options['statusRepository'])); $builder->addEventSubscriber(new CustomFormEventSubscriber($options['customFormModel'])); $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($options) { if ($options['customFormModel'] instanceof CompletenessCalculatorInterface) { $entity = $event->getData(); $entity->setPercentCompleteness($options['customFormModel']->calculateCompleteness($entity->getCustomData())); } }); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['widget'] == 'text') { $group = '_' . md5(microtime() . rand(500, 500000)); $hourOptions = $builder->get('hour')->getOptions(); $minOptions = $builder->get('minute')->getOptions(); $hourOptions['attr'] = array_merge($minOptions['attr'], array('size' => 1, 'maxlength' => 2, 'class' => 'gsClockPicker', 'data-clockField' => 'clockHours', 'data-clockGroup' => $group, 'data-increment' => 1)); $minOptions['attr'] = array_merge($minOptions['attr'], array('size' => 1, 'maxlength' => 2, 'class' => 'gsClockPicker', 'data-clockField' => 'clockMinutes', 'data-clockGroup' => $group, 'data-increment' => 5)); $builder->remove('hour')->add('hour', null, $hourOptions)->remove('minute')->add('minute', null, $minOptions); } $attr = array('class' => 'gsClockPicker', 'data-clockGroup' => $group, 'data-clockField' => 'clockMeridian'); $builder->add('meridian', 'checkbox', array('label' => 'AM', 'attr' => $attr, 'required' => false, 'label_attr' => array('class' => 'meridian', 'required' => false))); }
public function setDefault(\Symfony\Component\Form\FormBuilderInterface $builder) { $arrKeys = array('strPurpose', 'strPurposeDescription', 'intRepaymentMethod', 'intSourceOfIncome', 'intSalary', 'intMaritalStatus', 'intNumberOfChildren', 'strTypeOfSecurity', 'strTypeOfSecurityDescription'); foreach ($arrKeys as $key) { $methodName = 'get' . ucfirst($key); $builder->get($key)->setData($this->getCreditCreator()->{$methodName}()); } $files = $this->getCreditCreator()->getFiles(); $filesNames = array(); foreach ($files as $file) { $filesNames[] = $file['filename']; } $builder->get('filesName')->setData(join(', ', $filesNames)); }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('fechaSolicitud', 'collot_datetime', array('pickerOptions' => array('format' => 'dd/mm/yyyy', 'daysOfWeekDisabled' => '0,6', 'language' => 'es', 'autoclose' => 'true', 'minView' => 2), 'label' => 'Fecha de Solicitud', 'attr' => array('style' => 'margin-top:10px;')))->add('fechaPrestamo', 'collot_datetime', array('pickerOptions' => array('format' => 'dd/mm/yyyy', 'daysOfWeekDisabled' => '0,6', 'language' => 'es', 'autoclose' => 'true', 'minView' => 2), 'label' => 'Fecha de Prestamo', 'attr' => array('style' => 'margin-top:10px;')))->add('fechaDevolucion', 'collot_datetime', array('pickerOptions' => array('format' => 'dd/mm/yyyy', 'daysOfWeekDisabled' => '0,6', 'language' => 'es', 'autoclose' => 'true', 'minView' => 2), 'label' => 'Fecha para Devolución', 'attr' => array('style' => 'margin-top:10px;')))->add('fechaRegreso', 'collot_datetime', array('pickerOptions' => array('format' => 'dd/mm/yyyy', 'daysOfWeekDisabled' => '0,6', 'language' => 'es', 'autoclose' => 'true', 'minView' => 2), 'label' => 'Fecha real de Devolución', 'attr' => array('style' => 'margin-top:10px;')))->add('esInterno', 'checkbox', array('label' => '¿Es una actividad interna?'))->add('esAprobado', 'checkbox', array('label' => '¿Es aprobado el prestamo?'))->add('cantidadAprobada')->add('equipoPrestamo', 'entity', array('class' => 'HapEquiposBundle:Productos', 'query_builder' => function (\Doctrine\ORM\EntityRepository $repository) { return $repository->createQueryBuilder('s')->where('s.esPrestamo = 1'); }, 'placeholder' => 'Seleccione una opción')); $formModifier = function (FormInterface $form, Productos $equipo = null) { $cantidad = null === $equipo ? array() : $equipo->getInventario(); $ii = null == $cantidad ? null : $equipo->getId(); if ($ii == null) { $form->add('cantidad', 'entity', array('class' => 'HapEquiposBundle:Inventario', 'placeholder' => 'Seleccione una opción', 'choices' => $cantidad)); } else { $form->add('cantidad', 'entity', array('class' => 'HapEquiposBundle:Inventario', 'query_builder' => function (\Doctrine\ORM\EntityRepository $repository) use($ii) { return $repository->createQueryBuilder('s')->select('s')->where('s.productos = :i')->setParameter('i', $ii); }, 'placeholder' => 'Seleccione una opción')); } }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) { // this would be your entity, i.e. SportMeetup $data = $event->getData(); $formModifier($event->getForm(), $data->getEquipoPrestamo()); }); $builder->get('equipoPrestamo')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) { // It's important here to fetch $event->getForm()->getData(), as // $event->getData() will get you the client data (that is, the ID) $equipo = $event->getForm()->getData(); // since we've added the listener to the child, we'll have to pass on // the parent to the callback functions! $formModifier($event->getForm()->getParent(), $equipo); }); }
public function buildForm(FormBuilderInterface $builder, array $options) { $profileCountryIso = $this->profileCountryIso; $builder->add('country', 'entity', array('class' => 'ConnectionCoreBundle:Country', 'query_builder' => function (EntityRepository $er) use($profileCountryIso) { return $er->createQueryBuilder('c')->andWhere('c.iso IN (:iso)')->setParameter('iso', $profileCountryIso)->orderBy('c.priority', 'DESC'); }, 'property' => 'name', 'attr' => array('class' => 'master'), 'empty_value' => 'Any', 'required' => false)); $formModifier = function (FormInterface $form, Country $country = null) { if ($country) { $form->add('state', 'entity', array('class' => 'ConnectionCoreBundle:State', 'property' => 'name', 'attr' => array('class' => 'slave'), 'query_builder' => function (EntityRepository $er) use($country) { return $er->createQueryBuilder('s')->where('s.country = :country')->setParameter('country', $country)->orderBy('s.priority', 'DESC'); }, 'empty_value' => 'Any', 'required' => false)); } }; $builder->get('country')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) { $country = $event->getForm()->getData(); $formModifier($event->getForm()->getParent(), $country); }); // $builder->addEventListener( // FormEvents::PRE_SET_DATA, // function (FormEvent $event) use ($formModifier) { // $data = $event->getData(); // if ($data) { // $formModifier($event->getForm(), $data->getCountry()); // } // } // ); // add your custom field $builder->add('gender', 'entity', array('constraints' => new NotBlank(), 'class' => 'ConnectionUserBundle:Profile\\Gender', 'property' => 'name', 'expanded' => true, 'empty_value' => false, 'required' => true, 'label' => 'I am'))->add('seek', 'entity', array('constraints' => new NotBlank(), 'class' => 'ConnectionUserBundle:Profile\\Gender', 'property' => 'name', 'expanded' => true, 'required' => true, 'label' => 'Seeking')); $values = range(self::$ageFrom, self::$ageTo); $ageArray = array_combine($values, $values); $builder->add('ageFrom', 'choice', array('choices' => $ageArray, 'data' => self::$defaultSelectedFrom, 'empty_value' => 'Any', 'required' => false))->add('ageTo', 'choice', array('choices' => $ageArray, 'data' => self::$defaultSelectedTo, 'empty_value' => 'Any', 'required' => false))->add('lookingFor', 'entity', array('class' => 'ConnectionUserBundle:Profile\\LookingFor', 'property' => 'name', 'empty_value' => 'Anything', 'required' => false, 'multiple' => true))->add('languages', 'entity', array('class' => 'ConnectionCoreBundle:Language', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('l')->orderBy('l.priority', 'DESC'); }, 'property' => 'name', 'multiple' => true, 'expanded' => true, 'required' => false))->add('education', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Education', 'property' => 'name', 'multiple' => true, 'empty_value' => 'Any education', 'required' => false))->add('educationIvyLeague', 'choice', array('label' => 'Ivy league educated?', 'choices' => array(0 => 'No', 1 => 'Yes'), 'empty_value' => 'Not important', 'required' => false))->add('profession', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Profession', 'property' => 'name', 'empty_value' => 'Any profession', 'required' => false, 'multiple' => true))->add('income', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Income', 'property' => 'name', 'empty_value' => 'Any income', 'required' => false))->add('religion', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Religion', 'property' => 'name', 'label' => 'User religion', 'required' => false, 'multiple' => true))->add('maritalStatus', 'entity', array('class' => 'ConnectionUserBundle:Profile\\MaritalStatus', 'property' => 'name', 'multiple' => true, 'empty_value' => 'Any status', 'required' => false)); $heightArray = $this->_getHeightArray(); $builder->add('minimumHeight', 'choice', array('choices' => $heightArray, 'empty_value' => 'Any height', 'required' => false))->add('maximumHeight', 'choice', array('choices' => $heightArray, 'empty_value' => 'Any height', 'required' => false))->add('bodyType', 'entity', array('class' => 'ConnectionUserBundle:Profile\\BodyType', 'property' => 'name', 'empty_value' => 'Anything', 'required' => false))->add('eyeColor', 'entity', array('class' => 'ConnectionUserBundle:Profile\\EyeColor', 'property' => 'name', 'empty_value' => 'Any color', 'required' => false))->add('hairColor', 'entity', array('class' => 'ConnectionUserBundle:Profile\\HairColor', 'property' => 'name', 'empty_value' => 'Any color', 'required' => false))->add('smoking', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Smoking', 'property' => 'name', 'label' => 'Smoking?', 'empty_value' => 'Not important', 'required' => false))->add('drinking', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Drinking', 'property' => 'name', 'label' => 'Drinking?', 'empty_value' => 'Not important', 'required' => false))->add('haveChildren', 'entity', array('class' => 'ConnectionUserBundle:Profile\\HaveChildren', 'property' => 'name', 'label' => 'User has children?', 'empty_value' => 'Not important', 'required' => false))->add('wantChildren', 'entity', array('class' => 'ConnectionUserBundle:Profile\\WantChildren', 'property' => 'name', 'label' => 'User wants children?', 'empty_value' => 'Not important', 'required' => false))->add('livesWithChildren', 'entity', array('class' => 'ConnectionUserBundle:Profile\\LivesWithChildren', 'property' => 'name', 'label' => 'User lives with children?', 'empty_value' => 'Not important', 'required' => false))->add('openToPersonWithKids', 'entity', array('class' => 'ConnectionUserBundle:Profile\\OpenToPersonWithKids', 'property' => 'name', 'label' => 'User is open to dating a person with kids?', 'empty_value' => 'No preference', 'required' => false))->add('ethnicity', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Ethnicity', 'property' => 'name', 'empty_value' => 'Any ethnicity', 'required' => false))->add('zodiac', 'entity', array('class' => 'ConnectionUserBundle:Profile\\Zodiac', 'property' => 'name', 'empty_value' => 'Any sign', 'required' => false)); // ->add('zipCode', 'text', array( // 'required' => true // )) // // ->add('miles', 'choice', array( // 'constraints' => new NotBlank(), // 'label' => "Radius search", // 'choices' => array( // "5" => "5 miles", // "8" => "8 miles", // "10" => "10 miles", // "15" => "15 miles", // "25" => "25 miles", // "35" => "35 miles", // "50" => "50 miles", // "75" => "75 miles", // "100" => "100 miles", // "150" => "150 miles", // "200" => "200 miles", // ), // 'required' => true // )) $builder->add('searchType', 'hidden'); $builder->add('search', 'submit'); }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('attendee', AttendeeType::class)->add('coursepackageRadioSelections', CollectionType::class, ['entry_type' => CoursepackageRadioType::class]); foreach ($this->coursetypes as $key => $coursetype) { $builder->get('coursepackageRadioSelections')->add('coursepackageRadioSelection_' . $key, CoursepackageRadioType::class, ['coursetype' => $coursetype]); } }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('priceList', PriceListSelectType::NAME, ['label' => 'orob2b.pricing.pricelist.entity_label', 'create_enabled' => false, 'required' => true, 'constraints' => [new NotBlank()]])->add('unit', ProductUnitSelectionType::NAME, ['label' => 'orob2b.pricing.unit.label', 'empty_value' => 'orob2b.product.productunit.form.choose', 'constraints' => [new NotBlank()]])->add('price', PriceType::NAME, ['label' => 'orob2b.pricing.price.label', 'full_currency_list' => true]); // make value not empty $builder->get('price')->remove('value')->add('value', 'number', ['required' => true, 'constraints' => [new NotBlank(), new Range(['min' => 0]), new Decimal()]]); $this->addListeners($builder); }