<?php
/**
 * Hidden type handler
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Form\TypeHandler;

use VisualM\FormBundle\Entity\FormField;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Hidden type handler
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class HiddenTypeHandler implements FormTypeHandlerInterface
{
    /**
     * {@inheritdoc}
     */
    public function getSymfonyType(FormField $formField)
    {
        return HiddenTypeHandler::class;
    }

    /**
     * {@inheritdoc}
     */
    public function getOptions(FormField $formField)
    {
        $constraints = [];

        if ($formField->getRegex() != '' AND $formField->getRegex() != null) {
            $constraints[] = new Assert\Regex([ 'pattern' => $formField->getRegex()]);
        }

        if ($formField->getVerplicht()) {
            $constraints[] = new Assert\NotBlank();
        }

        return [
            'constraints' => $constraints
        ];
    }

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

