本文整理汇总了PHP中Symfony\Component\Form\FormBuilderInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilderInterface::getName方法的具体用法?PHP FormBuilderInterface::getName怎么用?PHP FormBuilderInterface::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilderInterface
的用法示例。
在下文中一共展示了FormBuilderInterface::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeButton
/**
* Stores a button for later rendering
*
* @param ButtonBuilder $buttonBuilder
* @param FormBuilderInterface $form
* @param string $position
*/
protected function storeButton(ButtonBuilder $buttonBuilder, FormBuilderInterface $form, $position)
{
if (!isset($this->buttons[$form->getName()])) {
$this->buttons[$form->getName()] = array();
}
$this->buttons[$form->getName()][$position] = $buttonBuilder;
}
示例2: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['text_field']) {
$options['text_field'] = $builder->getName() . '_name';
}
$builder->setAttribute('text_field', $options['text_field']);
$hidden_name = $builder->getName();
$text_name = $options['text_field'];
$repo = $this->em->getRepository($options['class']);
$builder->add($text_name, 'text', array('attr' => array('class' => 'autocomplete_input'), 'mapped' => $options['other_allowed']))->add($hidden_name, 'hidden', array('data_class' => $options['class'], 'empty_data' => null))->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($repo, $hidden_name, $text_name) {
$data = $event->getData();
$obj = null;
if (is_numeric($data[$hidden_name])) {
$obj = $repo->findOneBy(array('id' => $data[$hidden_name], 'name' => $data[$text_name]));
}
if (!$obj && !empty($data[$text_name])) {
$obj = $repo->findOneByName($data[$text_name]);
}
if (is_null($obj)) {
$event->setData(array($hidden_name => null, $text_name => $data[$text_name]));
} else {
$event->setData(array($hidden_name => $obj, $text_name => $obj->getName()));
}
});
}
示例3: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('valueType', ValueProviderType::class, ['label' => 'attribute.value_type', 'attr' => ['placeholder' => 'form.value_type.placeholder', 'help_text' => 'form.value_type.help_text']])->add('displayName', TextType::class, ['label' => 'attribute.display_name', 'attr' => ['class' => 'slugify', 'data-slugify-target' => '.slugify-target-' . $builder->getName(), 'data-slugify-separator' => '_', 'placeholder' => 'form.display_name.placeholder', 'help_text' => 'form.display_name.help_text', 'widget_col' => 6]])->add('name', TextType::class, ['label' => 'attribute.name', 'attr' => ['class' => 'slugify-target-' . $builder->getName(), 'placeholder' => 'form.name.placeholder', 'help_text' => 'form.name.help_text', 'widget_col' => 6]])->add('description', TextType::class, ['required' => false, 'label' => 'attribute.description', 'attr' => ['help_text' => 'form.description.help_text']])->add('sort', IntegerType::class, ['label' => 'attribute.sort', 'attr' => ['help_text' => 'form.sort.help_text', 'widget_col' => 2], 'empty_data' => 0, 'required' => false])->add('required', ChoiceType::class, ['choices' => [false => 'Not required', true => 'Required'], 'label' => 'Required', 'required' => true]);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$attribute = $event->getData();
$form = $event->getForm();
if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
// TODO Use Symfony's CollectionType here
$form->add('options', CollapsibleCollectionType::class, ['allow_add' => true, 'allow_delete' => true, 'type' => OptionType::class]);
}
});
}
示例4: buildForm
/**
* Adds a CSRF field to the form when the CSRF protection is enabled.
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['csrf_protection']) {
return;
}
$builder->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType()))));
}
示例5: 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);
});
}
示例6: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Creatd with createNamed('', ...) so likely an API request, might
// need to make this a little better in the future
$buildTabs = $builder->getName() === '' ? false : $options['build_tabs'];
$tabsData = $options['tabs_data'];
$formType = $builder->getType()->getInnerType();
$tabDefaults = ['inherit_data' => true];
foreach ($tabsData as $name => $data) {
$tabOptions = array_merge($tabDefaults, $data);
$forceTab = isset($data['force_tab']) ? $data['force_tab'] : false;
// Remove unused option
if ($forceTab) {
unset($tabOptions['force_tab']);
}
// Build Tab
if ($buildTabs || $forceTab) {
$parent = $builder->create($name, 'tab', $tabOptions);
$builder->add($parent);
// Just add it to the main form
} else {
$parent = $builder;
}
// Get method name
$method = sprintf('build%sForm', ucfirst($name));
if (!method_exists($formType, $method)) {
throw new \InvalidArgumentException(sprintf('Method "%s" does not exist in "%s"', $method, get_class($formType)));
}
// call buildTabNameForm
call_user_func([$formType, $method], $parent, $options, $builder->getData());
}
}
示例7: buildForm
/**
* Adds a CSRF field to the form when the CSRF protection is enabled.
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!$options['csrf_protection']) {
return;
}
$builder->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_token_manager'], $options['csrf_token_id'] ?: ($builder->getName() ?: get_class($builder->getType()->getInnerType())), $options['csrf_message'], $this->translator, $this->translationDomain));
}
示例8: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('valueType', 'value_provider', ['label' => 'attribute.value_type', 'attr' => ['placeholder' => 'form.value_type.placeholder', 'help_text' => 'form.value_type.help_text']])->add('displayName', TextType::class, ['label' => 'attribute.display_name', 'attr' => ['class' => 'slugify', 'data-slugify-target' => '.slugify-target-' . $builder->getName(), 'data-slugify-separator' => '_', 'placeholder' => 'form.display_name.placeholder', 'help_text' => 'form.display_name.help_text', 'widget_col' => 6]])->add('name', TextType::class, ['label' => 'attribute.name', 'attr' => ['class' => 'slugify-target-' . $builder->getName(), 'placeholder' => 'form.name.placeholder', 'help_text' => 'form.name.help_text', 'widget_col' => 6]])->add('description', TextType::class, ['required' => false, 'label' => 'attribute.description', 'attr' => ['help_text' => 'form.description.help_text']])->add('sort', IntegerType::class, ['label' => 'attribute.sort', 'attr' => ['help_text' => 'form.sort.help_text', 'widget_col' => 2], 'empty_data' => 0])->add('required', ChoiceType::class, ['choices' => [false => 'Not required', true => 'Required'], 'label' => 'Required', 'required' => true]);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$attribute = $event->getData();
$form = $event->getForm();
if ($attribute && in_array($attribute->getValueType(), ['checklist', 'select', 'radio'])) {
$form->add('options', 'collapsible_collection', ['allow_add' => true, 'allow_delete' => true, 'type' => $this->optionType]);
}
if ($attribute && $attribute->getValueType() == 'nested') {
$form->add('allowedSchemas', 'entity', ['class' => $this->schemaClass, 'property' => 'displayName', 'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('t')->orderBy('t.displayName', 'ASC');
}, 'by_reference' => false, 'expanded' => true, 'multiple' => true, 'label' => $this->translator->trans('attribute.allowed_schemas'), 'attr' => ['help_text' => $this->translator->trans('form.allowed_schemas.help_text')]]);
}
});
}
示例9: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber(new CollectionUploadSubscriber($builder->getName(), $options, $this->storage));
if (!$builder->hasAttribute('prototype')) {
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options']));
$builder->setAttribute('prototype', $prototype->getForm());
}
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$options['lastname_options']['required'] = $options['required'];
$options['firstname_options']['required'] = $options['required'];
if (!isset($options['options']['error_bubbling'])) {
$options['options']['error_bubbling'] = $options['error_bubbling'];
}
if (empty($options['lastname_name'])) {
$options['lastname_name'] = $builder->getName() . '01';
}
if (empty($options['firstname_name'])) {
$options['firstname_name'] = $builder->getName() . '02';
}
$builder->add($options['lastname_name'], 'text', array_merge($options['options'], $options['lastname_options']))->add($options['firstname_name'], 'text', array_merge($options['options'], $options['firstname_options']));
$builder->setAttribute('lastname_name', $options['lastname_name']);
$builder->setAttribute('firstname_name', $options['firstname_name']);
$builder->addEventSubscriber(new \Eccube\Event\FormEventSubscriber());
}
示例11: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// if($options['uploadConfig']['saveOriginal']){
// $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
// }
// var_dump($builder->getDataMapper());exit;
if ($options['uploadConfig']['saveOriginal']) {
$builder->add($options['uploadConfig']['saveOriginal'], 'text', array('attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
}
$builder->add($builder->getName(), 'text', array('attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
}
示例12: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$fileOptions = $options['file_widget_options'];
$field = empty($options['field']) ? $builder->getName() : $options['field'];
$builder->add('id', 'hidden');
$builder->add('delete', 'hidden', array('data' => 0));
$builder->add('file', 'file', $fileOptions);
$builder->addViewTransformer(new FileRepositoryViewTransformer($this->uploadManager, $options['repository_type'], $options['subdirectory'], $this->uploadRequestType));
$builder->addModelTransformer(new FileRepositoryModelTransformer($this->uploadManager, $options['repository_type'], $options['subdirectory'], $this->uploadRequestType));
$builder->addEventSubscriber(new FileRepositoryFormSubscriber($this->uploadManager, $options['repository_type'], $field));
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$options['zip01_options']['required'] = $options['required'];
$options['zip02_options']['required'] = $options['required'];
// required の場合は NotBlank も追加する
if ($options['required']) {
$options['options']['constraints'] = array_merge(array(new Assert\NotBlank(array())), $options['options']['constraints']);
}
if (!isset($options['options']['error_bubbling'])) {
$options['options']['error_bubbling'] = $options['error_bubbling'];
}
if (empty($options['zip01_name'])) {
$options['zip01_name'] = $builder->getName() . '01';
}
if (empty($options['zip02_name'])) {
$options['zip02_name'] = $builder->getName() . '02';
}
$builder->add($options['zip01_name'], 'text', array_merge_recursive($options['options'], $options['zip01_options']))->add($options['zip02_name'], 'text', array_merge_recursive($options['options'], $options['zip02_options']));
$builder->setAttribute('zip01_name', $options['zip01_name']);
$builder->setAttribute('zip02_name', $options['zip02_name']);
}
示例14: array
/**
* @param \Symfony\Component\Form\FormBuilderInterface $builder
* @param \Symfony\Component\Form\FormBuilderInterface $fileBuilder
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $fileEventDispatcher
* @param \FSi\Bundle\DoctrineExtensionsBundle\Form\EventListener\FileSubscriber $fileSubscriber
* @param \FSi\Bundle\DoctrineExtensionsBundle\Form\EventListener\RemovableFileSubscriber $removableFileSubscriber
*/
function it_should_build_form_remove_original_listener_and_register_own_listener(FormBuilderInterface $builder, FormBuilderInterface $fileBuilder, EventDispatcherInterface $fileEventDispatcher, FileSubscriber $fileSubscriber, RemovableFileSubscriber $removableFileSubscriber)
{
$builder->getName()->willReturn('file_field_name');
$builder->add('file_field_name', 'file_field_type', array('label' => false, 'error_bubbling' => true, 'some_file_field_option' => 'file_option_value'))->shouldBeCalled();
$builder->add('remove_field_name', 'remove_field_type', array('required' => false, 'label' => 'fsi_removable_file.remove', 'mapped' => false, 'translation_domain' => 'FSiDoctrineExtensionsBundle', 'some_remove_field_option' => 'remove_option_value'))->shouldBeCalled();
$builder->get('file_field_name')->willReturn($fileBuilder);
$fileBuilder->getEventDispatcher()->willReturn($fileEventDispatcher);
$fileEventDispatcher->getListeners(FormEvents::PRE_SUBMIT)->willReturn(array(array($fileSubscriber)));
$fileEventDispatcher->removeSubscriber($fileSubscriber)->shouldBeCalled();
$builder->addEventSubscriber($removableFileSubscriber)->shouldBeCalled();
$this->buildForm($builder, array('file_type' => 'file_field_type', 'file_options' => array('some_file_field_option' => 'file_option_value'), 'remove_name' => 'remove_field_name', 'remove_type' => 'remove_field_type', 'remove_options' => array('some_remove_field_option' => 'remove_option_value')));
}
示例15: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$isDefaultTranslation = 'defaultLocale' === $builder->getName();
// Custom mapper for translations
if (!$isDefaultTranslation) {
$builder->setDataMapper(new GedmoTranslationMapper());
}
foreach ($options['locales'] as $locale) {
if (isset($options['fields_options'][$locale])) {
$builder->add($locale, 'a2lix_translationsFields', array('fields' => $options['fields_options'][$locale], 'translation_class' => $options['translation_class'], 'inherit_data' => $isDefaultTranslation));
}
}
}