Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (70 sloc) 1.87 KB
<?php
/**
* This file is part of the Clastic package.
*
* (c) Dries De Peuter <dries@nousefreak.be>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Clastic\BackofficeBundle\Form\Type;
use Clastic\BackofficeBundle\Form\DataTransformer\EntityToIdTransformer;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Doctrine\Common\Persistence\ObjectManager;
/**
* @author Dries De Peuter <dries@nousefreak.be>
*/
class EntityHiddenType extends FormType
{
/**
* @var ObjectManager
*/
protected $objectManager;
/**
* @param ObjectManager $objectManager
*/
public function __construct(ObjectManager $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$transformer = new EntityToIdTransformer($this->objectManager, $options['class']);
$builder->addModelTransformer($transformer);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setRequired(['class'])
->setDefaults([
'invalid_message' => 'The entity does not exist.',
]);
}
public function getParent()
{
return HiddenType::class;
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'entity_hidden';
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
}