本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface::createNamedBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface::createNamedBuilder方法的具体用法?PHP FormFactoryInterface::createNamedBuilder怎么用?PHP FormFactoryInterface::createNamedBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactoryInterface
的用法示例。
在下文中一共展示了FormFactoryInterface::createNamedBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* {@inheritdoc}
*/
public function create($pollId)
{
$type = $this->formFactory->getType($this->type);
$type->setPollFields($pollId);
$builder = $this->formFactory->createNamedBuilder(sprintf('%s_%s', $this->name, $pollId), $type);
return $builder->getForm();
}
示例2: getForm
/**
* {@inheritdoc}
*/
public function getForm($group)
{
$block = $this->getSubtree($group);
$toAdd = array();
$bc = $block->toBlockConfig();
if (!$block->isEmpty()) {
$sbc = array();
/** @var $subblock GroupNodeDefinition */
foreach ($block as $subblock) {
$sbc += $subblock->toBlockConfig();
if (!$subblock->isEmpty()) {
/** @var $field FieldNodeDefinition */
foreach ($subblock as $field) {
$field->replaceOption('block', $block->getName())->replaceOption('subblock', $subblock->getName());
$toAdd[] = $field;
}
}
}
$bc[$block->getName()]['subblocks'] = $sbc;
}
$fb = $this->factory->createNamedBuilder($group, 'oro_config_form_type', null, array('block_config' => $bc));
foreach ($toAdd as $field) {
$this->addFieldToForm($fb, $field);
}
return $fb->getForm();
}
示例3: create
/**
* {@inheritdoc}
*/
public function create($id)
{
$type = $this->formFactory->getType($this->type);
$type->setId($id);
$builder = $this->formFactory->createNamedBuilder($type, sprintf('%s_%s', $this->name, $id));
return $builder->getForm();
}
示例4: getForm
/**
* @param string $widget
*
* @return FormInterface
* @throws InvalidArgumentException
*/
public function getForm($widget)
{
if (!$this->hasForm($widget)) {
throw new InvalidArgumentException(sprintf('Can\'t find form for widget "%s"', $widget));
}
$widgetConfig = $this->configProvider->getWidgetConfig($widget);
$fields = $widgetConfig[static::FORM_FIELDS_KEY];
$builder = $this->formFactory->createNamedBuilder($widget);
foreach ($fields as $name => $config) {
$field = new FieldNodeDefinition($name, $config);
$builder->add($field->getName(), $config['type'], $field->getOptions());
}
return $builder->getForm();
}
示例5: createComponentForm
/**
* @return FormComponent
*/
protected function createComponentForm()
{
$builder = $this->formFactory->createNamedBuilder($this->lookupPath('Nette\\Application\\UI\\Presenter'), $this->type, $this->entity, $this->options);
$component = $this->formComponentFactory->create($builder->getForm());
if ($this->theme) {
$component->onCreateView[] = function ($view, $component) {
$component->getRenderer()->setTheme($view, $this->theme);
};
}
$component->onSuccess[] = function ($entity) {
$this->processForm($entity);
};
return $component;
}
示例6: testEmbedLabelPrefix
public function testEmbedLabelPrefix()
{
$embedForm = $this->factory->createNamedBuilder($embedFormName = 'embed_form', FormType::class, null, ['label_prefix' => $embedLabelPrefix = 'embed_prefix'])->add($embedFieldName = 'embed_field');
$form = $this->factory->createBuilder(FormType::class, null, ['label_prefix' => $labelPrefix = 'prefix'])->add($embedForm)->add($fieldName = 'field')->getForm()->submit([]);
$view = $form->createView();
$fieldView = $view->children[$fieldName];
$embedFormView = $view->children[$embedFormName];
$embedFieldView = $embedFormView->children[$embedFieldName];
$this->assertArrayHasKey('label', $fieldView->vars);
$this->assertSame($labelPrefix . '.' . $fieldName, $fieldView->vars['label']);
$this->assertArrayHasKey('label', $embedFormView->vars);
$this->assertSame($labelPrefix . '.' . $embedFormName, $embedFormView->vars['label']);
$this->assertArrayHasKey('label', $embedFieldView->vars);
$this->assertSame($embedLabelPrefix . '.' . $embedFieldName, $embedFieldView->vars['label']);
}
示例7: createComponentForm
/**
* @return FormComponent
*/
protected function createComponentForm()
{
$builder = $this->formFactory->createNamedBuilder($this->lookupPath('Nette\\Application\\UI\\Presenter'), 'form', null, []);
$builder->add('firstname');
$builder->add('lastname');
$builder->add('email');
$builder->add('text');
$component = $this->formComponentFactory->create($builder->getForm());
$component->onSuccess[] = function (array $data) {
// process data
$this->getPresenter()->flashMessage('The form has been sucessfully sent.');
$this->getPresenter()->redirect('this');
};
return $component;
}
示例8: buildBasketElements
/**
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException
*
* @param $form
* @param $basketElements
*/
private function buildBasketElements($form, $basketElements)
{
if (null === $basketElements) {
return;
}
if (!$basketElements instanceof \ArrayAccess && !is_array($basketElements)) {
throw new UnexpectedTypeException($basketElements, 'array or \\ArrayAccess');
}
foreach ($basketElements as $basketElement) {
$basketElementBuilder = $this->factory->createNamedBuilder($basketElement->getPosition(), 'form', $basketElement, array('property_path' => '[' . $basketElement->getPosition() . ']', 'auto_initialize' => false));
$basketElementBuilder->setErrorBubbling(false);
$provider = $basketElement->getProductProvider();
$provider->defineBasketElementForm($basketElement, $basketElementBuilder);
$form->add($basketElementBuilder->getForm());
}
}
示例9: getFormBuilder
/**
* {@inheritdoc}
*/
public function getFormBuilder(FormFactoryInterface $factory)
{
if (!isset($this->formBuilder)) {
$this->formBuilder = $factory->createNamedBuilder($this->getResourceProperty(), $this->getFormType(), null, $this->buildFormOptions());
}
return $this->formBuilder;
}
示例10: getFormAddBasket
/**
* Returns a "add to basket" form for a specified product.
*
* @param ProductInterface $product A product instance
*
* @return FormView
*/
public function getFormAddBasket(ProductInterface $product)
{
$formBuilder = $this->formFactory->createNamedBuilder('add_basket', 'form', null, array('data_class' => $this->basketElementClass, 'csrf_protection' => false));
$this->productPool->getProvider($product)->defineAddBasketForm($product, $formBuilder, false);
$form = $formBuilder->getForm()->createView();
return $form;
}
示例11: createAclRolesForm
/**
* Gets the ACL roles form.
*
* @param \Sonata\AdminBundle\Util\AdminObjectAclData $data
*
* @return \Symfony\Component\Form\Form
*/
public function createAclRolesForm(AdminObjectAclData $data)
{
$aclValues = $data->getAclRoles();
$formBuilder = $this->formFactory->createNamedBuilder(self::ACL_ROLES_FORM_NAME, 'form');
$form = $this->buildForm($data, $formBuilder, $aclValues);
$data->setAclRolesForm($form);
return $form;
}
示例12: initForm
protected function initForm(FormFactoryInterface $factory, $data = null)
{
$builder = $factory->createNamedBuilder('subscriber', 'form', $data, array('data_class' => $this->getClassName()));
$builder->add('email', 'email', array('label' => 'admin.subscriber.list.email'));
$builder->add('created_at', 'date', array('label' => 'admin.subscriber.list.created_at', 'widget' => 'single_text'));
$builder->add('active', 'checkbox', array('label' => 'admin.subscriber.list.active'));
return $builder->getForm();
}
示例13: create
/**
* {@inheritdoc}
*/
public function create($name, $type = null, array $options = array())
{
if (null === $type && null === $this->getDataClass()) {
$type = 'text';
}
if (null !== $type) {
return $this->factory->createNamedBuilder($name, $type, null, $options, $this);
}
return $this->factory->createBuilderForProperty($this->getDataClass(), $name, null, $options, $this);
}
示例14: getForm
/**
* Returns a form with defined parameters.
*
* @param array $options
*
* @return Form
*/
public function getForm($options = array())
{
$options['csrf_protection'] = false;
$parameters = $this->getParameters();
$builder = $this->factory->createNamedBuilder('', 'form', $parameters, $options);
foreach ($parameters as $key => $value) {
$builder->add($key, 'hidden');
}
return $builder->getForm();
}
示例15: initForm
protected function initForm(FormFactoryInterface $factory, $data = null)
{
$builder = $factory->createNamedBuilder('news', 'form', $data, array('data_class' => $this->getClassName()));
$builder->add('title', 'text', array('label' => 'admin.news.list.title'));
$builder->add('date', 'date', array('label' => 'admin.news.list.date', 'widget' => 'single_text', 'required' => false));
$builder->add('created_at', 'date', array('label' => 'admin.news.list.created_at', 'widget' => 'single_text'));
$builder->add('visible', 'checkbox', array('label' => 'admin.news.list.visible', 'required' => false));
$builder->add('creator_email', 'email', array('label' => 'admin.news.list.creator_email'));
$builder->add('photo', 'fsi_image', array('label' => 'admin.news.list.photo'));
$builder->add('tags', 'collection', array('type' => new TagType(), 'label' => 'admin.news.list.tags', 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false));
return $builder->getForm();
}