propel-bundle/Form/Type/TranslationCollectionType.php

83 lines
2.3 KiB
PHP
Raw Normal View History

2013-12-12 16:01:41 +01:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2016-02-11 19:14:03 +01:00
namespace Propel\Bundle\PropelBundle\Form\Type;
2013-12-12 16:01:41 +01:00
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\Form\FormBuilderInterface;
2015-08-06 19:02:55 +02:00
use Symfony\Component\OptionsResolver\OptionsResolver;
2016-02-11 19:14:03 +01:00
use Propel\Bundle\PropelBundle\Form\EventListener\TranslationCollectionFormListener;
2015-08-06 19:02:55 +02:00
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
2013-12-12 16:01:41 +01:00
/**
* form type for i18n-columns in propel
*
* @author Patrick Kaufmann
*/
class TranslationCollectionType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (!isset($options['options']['data_class']) || null === $options['options']['data_class']) {
throw new MissingOptionsException('data_class must be set');
}
if (!isset($options['options']['columns']) || null === $options['options']['columns']) {
throw new MissingOptionsException('columns must be set');
}
$listener = new TranslationCollectionFormListener($options['languages'], $options['options']['data_class']);
$builder->addEventSubscriber($listener);
}
public function getParent()
{
return 'collection';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'propel_translation_collection';
}
/**
* {@inheritdoc}
*/
2015-08-06 19:02:55 +02:00
public function configureOptions(OptionsResolver $resolver)
2013-12-12 16:01:41 +01:00
{
$resolver->setRequired(array(
'languages'
));
$resolver->setDefaults(array(
'type' => 'propel_translation',
'allow_add' => false,
'allow_delete' => false,
'options' => array(
'data_class' => null,
'columns' => null
)
));
}
2015-08-06 19:02:55 +02:00
// BC for SF < 2.7
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
2013-12-12 16:01:41 +01:00
}