本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface::createNamed方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface::createNamed方法的具体用法?PHP FormFactoryInterface::createNamed怎么用?PHP FormFactoryInterface::createNamed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactoryInterface
的用法示例。
在下文中一共展示了FormFactoryInterface::createNamed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* {@inheritdoc}
*/
public function handle(Request $request, FormHandlerInterface $handler, FormInterface $form = null)
{
if (null !== $form) {
$handler->setForm($form);
} elseif (null === ($form = $handler->getForm())) {
if ($handler instanceof NamedFormHandlerInterface && null !== ($name = $handler->getName())) {
$form = $this->form_factory->createNamed($name, $handler->getType(), $handler->getData(), $handler->getOptions());
} else {
$form = $this->form_factory->create($handler->getType(), $handler->getData(), $handler->getOptions());
}
if (!$form instanceof FormInterface) {
throw new FormNotFoundException($handler);
}
// set the form which is associated with the handler
$handler->setForm($form);
}
$form->handleRequest($request);
if (!$form->isSubmitted()) {
return null;
}
if ($form->isValid()) {
if ($handler instanceof FormSuccessHandlerInterface) {
return $handler->onSuccess($request);
}
} elseif ($handler instanceof FormFailureHandlerInterface) {
return $handler->onFailure($request);
}
}
示例2: buildForm
/**
* Builds proper field form.
*
* @param FormEvent $event
*/
public function buildForm(FormEvent $event)
{
if (null === ($fieldValue = $event->getData())) {
return;
}
$form = $event->getForm();
$options = array('label' => $fieldValue->getPresentation(), 'auto_initialize' => false, 'attr' => array('data-field-name' => $fieldValue->getName(), 'data-field-addable' => false));
if (is_array($fieldValue->getConfiguration())) {
$options = array_merge_recursive($options, $fieldValue->getConfiguration());
}
$name = 'value';
if (FieldTypes::CHOICE === $fieldValue->getType()) {
$option = $fieldValue->getField()->getOption();
$sortBy = $fieldValue->getField()->getOrder();
$type = new OptionValueChoiceType($option, $sortBy);
if ($fieldValue->getAllowMultiple()) {
$name = 'values';
$options['multiple'] = true;
$options['expanded'] = true;
}
$options['attr']['data-field-addable'] = $fieldValue->isAddable();
} else {
$type = $fieldValue->getType();
}
$form->remove('field')->add($this->factory->createNamed($name, $type, null, $options));
}
示例3: testSetInvalidYearsOption
public function testSetInvalidYearsOption()
{
$help = 'Having trouble with the internets? Tell us about it.';
$form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, ['help' => $help]);
$view = $form->createView();
$this->assertSame($help, $view->vars['help']);
}
示例4: addConfigurationFields
/**
* @param FormInterface $form
* @param string $ruleType
* @param array $data
*/
protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = [])
{
/** @var RuleCheckerInterface $checker */
$checker = $this->checkerRegistry->get($ruleType);
$configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, ['auto_initialize' => false]);
$form->add($configurationField);
}
示例5: createAndHandle
public function createAndHandle($name, $type, IEntity $entity)
{
$request = $this->request_stack->getMasterRequest();
$form = $this->form_factory->createNamed($name, $type, $entity, ['method' => 'POST']);
$form->handleRequest($request);
return $form;
}
示例6: createForm
/**
* @return FormInterface
*/
public function createForm()
{
$user = $this->userDiscriminator->getCurrentUserConfig();
$type = $user->getFormType($this->type);
$name = $user->getFormName($this->type);
$validationGroups = $user->getFormValidationGroups($this->type);
return $this->formFactory->createNamed($name, $type, null, array('validation_groups' => $validationGroups));
}
示例7: addAttributeAsLabelField
/**
* @param FormEvent $event
*/
public function addAttributeAsLabelField(FormEvent $event)
{
$data = $event->getData();
if ($data instanceof FamilyInterface && $data->getId()) {
$form = $event->getForm();
$form->add($this->factory->createNamed('attributeAsLabel', 'entity', $data->getAttributeAsLabel(), ['required' => true, 'label' => 'Attribute used as label', 'class' => $this->attributeClass, 'choices' => $data->getAttributeAsLabelChoices(), 'auto_initialize' => false, 'select2' => true, 'disabled' => !$this->securityFacade->isGranted('pim_enrich_family_edit_properties')]));
}
}
示例8: preSetData
/**
* @param FormEvent $event
*/
public function preSetData(FormEvent $event)
{
$taxon = $event->getData();
if (null === $taxon) {
return;
}
$event->getForm()->add($this->factory->createNamed('parent', TaxonChoiceType::class, $taxon->getParent(), ['filter' => $this->getFilterTaxonOption($taxon), 'required' => false, 'label' => 'sylius.form.taxon.parent', 'placeholder' => '---', 'auto_initialize' => false]));
}
示例9: preSetData
/**
* Builds proper taxon form after setting the product.
*
* @param FormEvent $event
*/
public function preSetData(FormEvent $event)
{
$taxon = $event->getData();
if (null === $taxon) {
return;
}
$event->getForm()->add($this->factory->createNamed('parent', 'sylius_taxon_choice', $taxon->getParent(), array('taxonomy' => $taxon->getTaxonomy(), 'filter' => $this->getFilterTaxonOption($taxon), 'required' => false, 'label' => 'sylius.form.taxon.parent', 'empty_value' => '---', 'auto_initialize' => false)));
}
示例10: populateEntityFromRequest
/**
* Return the populated entity if everything is ok,
* if the data is not valid will throw a FormValidationException
*
* @param $formServiceName
* @param $entityToPopulate
*
* @return FormInterface
*/
public function populateEntityFromRequest($formServiceName, $entityToPopulate, $nameForm = '')
{
$form = $this->formFactory->createNamed($nameForm, $formServiceName, $entityToPopulate);
$form->handleRequest($this->requestStack->getCurrentRequest());
if (!$form->isSubmitted()) {
$form->submit([]);
}
return $form;
}
示例11: processForm
/**
* @param Request $request
* @return View
*/
private function processForm(Request $request)
{
$form = $this->formFactory->createNamed('', 'user_search');
$form->handleRequest($request);
if (!$form->isEmpty() && !$form->isValid()) {
return new View($form, 400);
}
return new View($this->useCase->listUsers($form->getData()), 200);
}
示例12: createForm
/**
* {@inheritdoc}
*/
public function createForm(array $options = [], $data = null)
{
$options = array_merge(['validation_groups' => $this->validationGroups], $options);
$form = $this->formFactory->createNamed($this->name, $this->type, null, $options);
if (null !== $data) {
$form->setData($data);
}
return $form;
}
示例13: create
/**
* {@inheritdoc}
*/
public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource)
{
$formType = $requestConfiguration->getFormType();
$formOptions = $requestConfiguration->getFormOptions();
if ($requestConfiguration->isHtmlRequest()) {
return $this->formFactory->create($formType, $resource, $formOptions);
}
return $this->formFactory->createNamed('', $formType, $resource, array_merge($formOptions, ['csrf_protection' => false]));
}
示例14: processForm
/**
* @param User $user
* @param Request $request
* @return View
*/
private function processForm(User $user, Request $request)
{
$form = $this->formFactory->createNamed('', 'user_create', $user);
$form->handleRequest($request);
if (!$form->isValid()) {
return new View($form, 400);
}
$this->useCase->createUser($user, false);
return new View($user, 201, ['Location' => $this->router->generate('arkon_user_getUser', ['id' => $user->getId()], true)]);
}
示例15: addConfigurationFields
/**
* @param FormEvent $event
*/
public function addConfigurationFields(FormEvent $event)
{
$attribute = $event->getData();
$form = $event->getForm();
try {
$requiredFields = $this->factory->createNamed('configuration', 'sylius_attribute_type_configuration_' . $attribute->getType(), null, ['auto_initialize' => false, 'label' => 'sylius.form.attribute_type.configuration']);
$form->add($requiredFields);
} catch (InvalidArgumentException $exception) {
}
}