<?php
/**
 * GoogleRecaptchaTypeHandler
 *
 * @author Bertin van den Ham <b.vandenham@visualmedia.nl>
 */

namespace VisualM\FormBundle\Form\TypeHandler;

use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Validator\Constraints as Assert;
use VisualM\FormBundle\Entity\FormFieldInterface;
use VisualM\FormBundle\Form\Constraint\GoogleRecaptchaConstraint;
use VisualM\FormBundle\Form\Type\GoogleRecaptchaType;

/**
 * GoogleRecaptcha Type Handler
 *
 * @author Bertin van den Ham <b.vandenham@visualmedia.nl>
 */
class GoogleRecaptchaTypeHandler implements FormTypeHandlerInterface
{
    /**
     * {@inheritdoc}
     */
    public function getSymfonyType(FormFieldInterface $formField)
    {
        return HiddenType::class;
    }

    /**
     * {@inheritdoc}
     */
    public function getOptions(FormFieldInterface $formField)
    {
    	// Custom Google Recaptcha Constraint
	    $constraints[] = new GoogleRecaptchaConstraint();

        return [
            'constraints' => $constraints,
            'error_bubbling' => true
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function normalizeValue(FormFieldInterface $formField, $value)
    {
        return $value;
    }
}
