本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::get方法的具体用法?PHP FormBuilderInterface::get怎么用?PHP FormBuilderInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
});
}
示例2: buildForm
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');
}
示例3: buildForm
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;
}));
}
示例4: buildForm
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);
});
}
示例5: buildForm
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);
}
示例6: buildForm
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);
}
示例7: buildForm
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());
}
示例8: buildForm
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));
}
示例9: buildForm
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');
}
示例10: buildForm
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);
});
}
示例11: buildForm
/**
* @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));
}
示例12: buildForm
/**
* @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));
}
示例13: buildForm
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']]);
}
示例14: buildForm
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']));
}
示例15: buildForm
/**
* @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();
}