<?php
/**
 * LanguageTagSetType FormType
 *
 * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
 */
namespace VisualM\TagManagerBundle\Form\Type;

use Exception;

use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

use VisualM\TagManagerBundle\Model\MetaTagSetModel;

/**
 * LanguageTagSetType FormType
 *
 * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
 */
class LanguageTagSetType extends AbstractType
{
   	/**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    	$configuration = $options['data'];

        $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($configuration) {
            $form = $event->getForm();
            $data = $event->getData();

            $form->add('selfReferencing', ChoiceType::class, array(
                'choices' => array(
                    false => 'meta_tag_set.self_referencing.false',
                    true => 'meta_tag_set.self_referencing.true',
                ),
                'placeholder' => 'meta_tag_set.self_referencing.empty',
                'label' => 'meta_tag_set.self_referencing.label',
            ));
        });

        $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
            $form = $event->getForm();
            $data = $event->getData();

            $data['selfReferencing'] = $form->get('selfReferencing')->getData();
        });
    }
}




