Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (84 sloc) 2.2 KB
<?php
/*
* This file is part of the Symfony package.
*
* (c) Olivier Chauvel <olivier@generation-multiple.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Genemu\Bundle\FormBundle\Form\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Genemu\Bundle\FormBundle\Gd\Type\Captcha;
use Genemu\Bundle\FormBundle\Form\Core\Validator\CaptchaValidator;
/**
* CaptchaType
*
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
class CaptchaType extends AbstractType
{
private $captcha;
private $options;
/**
* Constructs
*
* @param Captcha $captcha
* @param array $options
*/
public function __construct(Captcha $captcha, array $options)
{
$this->captcha = $captcha;
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->captcha->setOptions($options);
$builder->addValidator(new CaptchaValidator($this->captcha));
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$captcha = $this->captcha;
$view->vars = array_replace($view->vars, array(
'value' => '',
'src' => $captcha->getBase64($options['format']),
'width' => $captcha->getWidth(),
'height' => $captcha->getHeight(),
));
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaults = array_merge(
array('attr' => array('autocomplete' => 'off')),
$this->options
);
$resolver->setDefaults($defaults);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'text';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'genemu_captcha';
}
}
Something went wrong with that request. Please try again.