Merge branch 'admin' of https://github.com/thelia/thelia into admin

This commit is contained in:
franck
2013-07-02 15:54:24 +02:00
7 changed files with 81 additions and 46 deletions

View File

@@ -23,17 +23,16 @@
namespace Thelia\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Choice;
class AdminLogin extends AbstractType {
class AdminLogin extends BaseForm {
public function buildForm(FormBuilderInterface $builder, array $options)
protected function buildForm()
{
return $builder
$this->form
->add("username", "text", array(
"constraints" => array(
new NotBlank(),
@@ -48,13 +47,4 @@ class AdminLogin extends AbstractType {
->add("remember_me", "checkbox");
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return "admin_login";
}
}

View File

@@ -32,30 +32,43 @@ use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
use Symfony\Component\Validator\Validation;
use Thelia\Model\ConfigQuery;
class BaseForm {
abstract class BaseForm {
/**
* @param Request $request
* @return \Symfony\Component\Form\FormFactoryInterface
* @var \Symfony\Component\Form\FormFactoryInterface
*/
public static function getFormFactory(Request $request, $secret = null)
protected $form;
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
{
$validator = Validation::createValidator();
$form = Forms::createFormFactoryBuilder()
$this->form = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->addExtension(
new CsrfExtension(
new SessionCsrfProvider(
$request->getSession(),
$secret ?: ConfigQuery::read("form.secret", md5(__DIR__))
isset($option["secret"]) ? $option["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
)
)
)
->addExtension(new ValidatorExtension($validator))
->getFormFactory();
->getFormFactory()
->createBuilder($type, $data, $options);
;
return $form;
$this->buildForm();
}
/**
* @return \Symfony\Component\Form\Form
*/
public function getForm()
{
return $this->form->getForm();
}
abstract protected function buildForm();
}

View File

@@ -24,31 +24,25 @@ namespace Thelia\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
class CustomerCreation extends AbstractType
class CustomerCreation extends BaseForm
{
public function buildForm(FormBuilderInterface $builder, array $options)
protected function buildForm()
{
return $builder->add("name", "text")
$this->form->add("name", "text")
->add("email", "email", array(
"attr" => array(
"class" => "field"
),
"label" => "email"
"label" => "email",
"constraints" => array(
new NotBlank()
)
)
)
->add('age', 'integer');
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return "customer creation";
}
}