gist/src/Gist/Form/AbstractForm.php

73 lines
1.4 KiB
PHP
Raw Normal View History

2015-05-05 22:04:04 +02:00
<?php
namespace Gist\Form;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Translation\Translator;
/**
2016-11-13 00:44:23 +01:00
* Class AbstractForm.
*
2015-05-05 22:04:04 +02:00
* @author Simon Vieille <simon@deblan.fr>
*/
abstract class AbstractForm
{
2016-11-13 00:44:23 +01:00
/**
* The builder.
*
* @var Symfony\Component\Form\FormBuilder
*/
2015-05-05 22:04:04 +02:00
protected $builder;
2016-11-13 00:44:23 +01:00
/**
* The translator.
*
* @var Translator
*/
2015-05-05 22:04:04 +02:00
protected $translator;
2016-11-13 00:44:23 +01:00
/**
* __construct.
*
* @param FormFactory $formFactory
* @param Translator $translator
* @param mixed $data
* @param array $formFactoryOptions
*/
2015-11-21 15:04:41 +01:00
public function __construct(FormFactory $formFactory, Translator $translator, $data = null, $formFactoryOptions = array())
2015-05-05 22:04:04 +02:00
{
$this->translator = $translator;
2015-11-21 18:28:48 +01:00
$this->builder = $formFactory->createNamedBuilder($this->getName(), 'form', $data, $formFactoryOptions);
2015-05-05 22:04:04 +02:00
}
2016-11-13 00:44:23 +01:00
/**
* Returns the form from the builder.
*
* @return Symfony\Component\Form\Form
*/
2015-05-09 01:03:51 +02:00
public function getForm()
{
return $this->builder->getForm();
}
2016-11-13 00:44:23 +01:00
/**
* Returns the form's name.
*
* @return string
*/
2015-11-21 18:28:48 +01:00
public function getName()
{
return 'form';
}
2016-11-13 00:44:23 +01:00
/**
* Builds the form.
*
* @param array $options
*
* @return Symfony\Component\Form\FormBuilder
*/
2015-05-05 22:04:04 +02:00
abstract public function build(array $options = array());
}