Added the possibility of overriding the width & height in the options
This commit is contained in:
parent
959cf84805
commit
ab882512f1
|
@ -3,6 +3,6 @@ services:
|
|||
# captcha type
|
||||
captcha.type:
|
||||
class: Gregwar\CaptchaBundle\Type\CaptchaType
|
||||
arguments: [@session, @service_container]
|
||||
arguments: [@session, %gregwar_captcha.image.width%, %gregwar_captcha.image.height%]
|
||||
tags:
|
||||
- { name: form.type, alias: captcha }
|
||||
|
|
|
@ -21,18 +21,18 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
|
|||
*/
|
||||
class CaptchaType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* The image height
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* The image width
|
||||
* @var integer
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* The image height
|
||||
* @var integer
|
||||
*/
|
||||
protected $height;
|
||||
|
||||
/**
|
||||
* The session
|
||||
* @var Symfony\Component\HttpFoundation\Session
|
||||
|
@ -42,11 +42,11 @@ class CaptchaType extends AbstractType
|
|||
private $key = 'captcha';
|
||||
|
||||
|
||||
public function __construct(Session $session, ContainerInterface $container)
|
||||
public function __construct(Session $session, $width, $height)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->height = $container->getParameter('gregwar_captcha.image.height');
|
||||
$this->width = $container->getParameter('gregwar_captcha.image.width');
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,20 @@ class CaptchaType extends AbstractType
|
|||
$view->set('captcha_code', $generator->getCode($this->width, $this->height));
|
||||
$view->set('captcha_width', $this->width);
|
||||
$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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue