open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/GenerateForm/Strategies/ContactStrategy.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace OpenOrchestra\Backoffice\GenerateForm\Strategies;

use OpenOrchestra\DisplayBundle\DisplayBlock\Strategies\ContactStrategy as BaseContactStrategy;
use OpenOrchestra\ModelInterface\Model\BlockInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
 * Class ContactStrategy
 */
class ContactStrategy extends AbstractBlockStrategy
{
    /**
     * @param BlockInterface $block
     *
     * @return bool
     */
    public function support(BlockInterface $block)
    {
        return BaseContactStrategy::NAME === $block->getComponent();
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('recipient', 'email', array(
            'label' => 'open_orchestra_backoffice.block.contact.recipient',
            'constraints' => new NotBlank(),
            'group_id' => 'data',
            'sub_group_id' => 'content',
        ));
        $builder->add('signature', 'text', array(
            'label' => 'open_orchestra_backoffice.block.contact.signature',
            'constraints' => new Email(),
            'group_id' => 'data',
            'sub_group_id' => 'content',
        ));
        $builder->remove('maxAge');
    }

    /**
     * @return array
     */
    public function getDefaultConfiguration()
    {
        return array(
            'maxAge' => 0
        );
    }

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

}