2012-07-30 08:07:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Form;
|
|
|
|
|
|
|
|
use Symfony\Component\Form\Extension\Core\CoreExtension;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point of the Form component.
|
|
|
|
*
|
|
|
|
* Use this class to conveniently create new form factories:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* use Symfony\Component\Form\Forms;
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $formFactory = Forms::createFormFactory();
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $form = $formFactory->createBuilder()
|
|
|
|
* ->add('firstName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
* ->add('lastName', 'Symfony\Component\Form\Extension\Core\Type\TextType')
|
|
|
|
* ->add('age', 'Symfony\Component\Form\Extension\Core\Type\IntegerType')
|
2019-01-05 06:17:43 +00:00
|
|
|
* ->add('color', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
|
|
|
|
* 'choices' => array('Red' => 'r', 'Blue' => 'b'),
|
2018-08-28 22:39:52 +01:00
|
|
|
* ))
|
|
|
|
* ->getForm();
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
|
|
|
* You can also add custom extensions to the form factory:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $formFactory = Forms::createFormFactoryBuilder()
|
|
|
|
* ->addExtension(new AcmeExtension())
|
|
|
|
* ->getFormFactory();
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
|
|
|
* If you create custom form types or type extensions, it is
|
|
|
|
* generally recommended to create your own extensions that lazily
|
|
|
|
* load these types and type extensions. In projects where performance
|
|
|
|
* does not matter that much, you can also pass them directly to the
|
|
|
|
* form factory:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $formFactory = Forms::createFormFactoryBuilder()
|
|
|
|
* ->addType(new PersonType())
|
|
|
|
* ->addType(new PhoneNumberType())
|
|
|
|
* ->addTypeExtension(new FormTypeHelpTextExtension())
|
|
|
|
* ->getFormFactory();
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
|
|
|
* Support for the Validator component is provided by ValidatorExtension.
|
|
|
|
* This extension needs a validator object to function properly:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* use Symfony\Component\Validator\Validation;
|
|
|
|
* use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $validator = Validation::createValidator();
|
|
|
|
* $formFactory = Forms::createFormFactoryBuilder()
|
|
|
|
* ->addExtension(new ValidatorExtension($validator))
|
|
|
|
* ->getFormFactory();
|
2012-07-30 08:07:04 +01:00
|
|
|
*
|
2012-07-30 08:52:50 +01:00
|
|
|
* Support for the Templating component is provided by TemplatingExtension.
|
|
|
|
* This extension needs a PhpEngine object for rendering forms. As second
|
|
|
|
* argument you should pass the names of the default themes. Here is an
|
|
|
|
* example for using the default layout with "<div>" tags:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* use Symfony\Component\Form\Extension\Templating\TemplatingExtension;
|
2012-07-30 08:52:50 +01:00
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $formFactory = Forms::createFormFactoryBuilder()
|
|
|
|
* ->addExtension(new TemplatingExtension($engine, null, array(
|
|
|
|
* 'FrameworkBundle:Form',
|
|
|
|
* )))
|
|
|
|
* ->getFormFactory();
|
2012-07-30 08:52:50 +01:00
|
|
|
*
|
|
|
|
* The next example shows how to include the "<table>" layout:
|
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* use Symfony\Component\Form\Extension\Templating\TemplatingExtension;
|
2012-07-30 08:52:50 +01:00
|
|
|
*
|
2018-08-28 22:39:52 +01:00
|
|
|
* $formFactory = Forms::createFormFactoryBuilder()
|
|
|
|
* ->addExtension(new TemplatingExtension($engine, null, array(
|
|
|
|
* 'FrameworkBundle:Form',
|
|
|
|
* 'FrameworkBundle:FormTable',
|
|
|
|
* )))
|
|
|
|
* ->getFormFactory();
|
2012-07-30 08:52:50 +01:00
|
|
|
*
|
2012-07-30 08:07:04 +01:00
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
|
|
|
final class Forms
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Creates a form factory with the default configuration.
|
|
|
|
*
|
2016-06-28 06:50:50 +01:00
|
|
|
* @return FormFactoryInterface The form factory
|
2012-07-30 08:07:04 +01:00
|
|
|
*/
|
|
|
|
public static function createFormFactory()
|
|
|
|
{
|
|
|
|
return self::createFormFactoryBuilder()->getFormFactory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a form factory builder with the default configuration.
|
|
|
|
*
|
2016-06-28 06:50:50 +01:00
|
|
|
* @return FormFactoryBuilderInterface The form factory builder
|
2012-07-30 08:07:04 +01:00
|
|
|
*/
|
|
|
|
public static function createFormFactoryBuilder()
|
|
|
|
{
|
|
|
|
$builder = new FormFactoryBuilder();
|
|
|
|
$builder->addExtension(new CoreExtension());
|
|
|
|
|
|
|
|
return $builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class cannot be instantiated.
|
|
|
|
*/
|
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|