Added the possibility of overriding the width & height in the options

This commit is contained in:
Gregwar 2011-09-09 19:46:12 +02:00
parent 959cf84805
commit ab882512f1
2 changed files with 24 additions and 11 deletions

View File

@ -3,6 +3,6 @@ services:
# captcha type # captcha type
captcha.type: captcha.type:
class: Gregwar\CaptchaBundle\Type\CaptchaType class: Gregwar\CaptchaBundle\Type\CaptchaType
arguments: [@session, @service_container] arguments: [@session, %gregwar_captcha.image.width%, %gregwar_captcha.image.height%]
tags: tags:
- { name: form.type, alias: captcha } - { name: form.type, alias: captcha }

View File

@ -21,18 +21,18 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
*/ */
class CaptchaType extends AbstractType class CaptchaType extends AbstractType
{ {
/**
* The image height
* @var integer
*/
protected $height;
/** /**
* The image width * The image width
* @var integer * @var integer
*/ */
protected $width; protected $width;
/**
* The image height
* @var integer
*/
protected $height;
/** /**
* The session * The session
* @var Symfony\Component\HttpFoundation\Session * @var Symfony\Component\HttpFoundation\Session
@ -42,11 +42,11 @@ class CaptchaType extends AbstractType
private $key = 'captcha'; private $key = 'captcha';
public function __construct(Session $session, ContainerInterface $container) public function __construct(Session $session, $width, $height)
{ {
$this->session = $session; $this->session = $session;
$this->height = $container->getParameter('gregwar_captcha.image.height'); $this->width = $width;
$this->width = $container->getParameter('gregwar_captcha.image.width'); $this->height = $height;
} }
@ -66,6 +66,19 @@ class CaptchaType extends AbstractType
$view->set('captcha_height', $this->height); $view->set('captcha_height', $this->height);
} }
public function getDefaultOptions(array $options = array())
{
if (isset($options['width'])) {
$this->width = $options['width'];
$this->height = $options['height'];
}
return array(
'width' => $this->width,
'height' => $this->height
);
}
public function getParent(array $options) public function getParent(array $options)
{ {
return 'text'; return 'text';