<?php

namespace OfficeBrain\Bundle\SeoBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints ;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\Validator\Constraints\NotBlankValidator;
use Symfony\Component\Form\FormError;

class SeoDetailType extends AbstractType
{
    public function __construct($action,$positionValue)
    {
        //$this->container = $container;
        
        if($positionValue==1)
            $this->postion = 1;
        else
            $this->postion = 0;
    }
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('IsPrefix', 'choice', array(
                'choices' => array('0' => 'postfix', '1' => 'prefix'),
                'expanded' => true,
                'data'=>$this->postion

                ))
            ->add('productSku','text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array()),
                        //new Constraints\Length(array('max' =>'160','maxMessage' => 'Seo.metatitle.max')),
                    ),
                ))
            ->add('metaTitle',  'text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array()),
                        //new Constraints\Length(array('max' =>'55','maxMessage' => 'Meta Title maximum 55 character allowed')),
                    ),
                ))
            ->add('metaKeyWords',  'text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array()),
                        //new Constraints\Length(array( 'max' =>'120','maxMessage' => 'Meta Keywords maximum 120 character allowed')),
                    ),
                ))
            ->add('metaDescription',  'text', array (
                    'required'  => false,
                    'constraints' => array(
                        new Constraints\NotBlank(array()),
                        //new Constraints\Length(array( 'max' =>'155','maxMessage' => 'Meta Description maximum 155 character allowed')),
                    ),
                ))
        ;
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'OfficeBrain\Bundle\SeoBundle\Entity\SeoDetail'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'officebrain_bundle_seobundle_seodetail';
    }
}
