|
@@ -17,6 +17,7 @@ use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\Form\FormView;
|
|
use Symfony\Component\Form\FormView;
|
|
|
|
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
|
|
|
|
|
use Sonata\AdminBundle\Form\EventListener\MergeCollectionListener;
|
|
use Sonata\AdminBundle\Form\EventListener\MergeCollectionListener;
|
|
use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList;
|
|
use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList;
|
|
@@ -26,27 +27,36 @@ use Sonata\AdminBundle\Model\ModelManagerInterface;
|
|
|
|
|
|
class ModelReferenceType extends AbstractType
|
|
class ModelReferenceType extends AbstractType
|
|
{
|
|
{
|
|
- private $parent;
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
*/
|
|
*/
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
{
|
|
$builder->prependClientTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
|
|
$builder->prependClientTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+ public function createBuilder($name, FormFactoryInterface $factory, array $options)
|
|
|
|
+ {
|
|
|
|
+ return parent::createBuilder($name, $factory, $options);
|
|
$this->parent = $options['parent'];
|
|
$this->parent = $options['parent'];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* {@inheritDoc}
|
|
* {@inheritDoc}
|
|
*/
|
|
*/
|
|
- public function getDefaultOptions()
|
|
|
|
|
|
+ public function getDefaultOptions(OptionsResolverInterface $resolver)
|
|
{
|
|
{
|
|
return array(
|
|
return array(
|
|
'model_manager' => null,
|
|
'model_manager' => null,
|
|
'class' => null,
|
|
'class' => null,
|
|
'parent' => 'hidden',
|
|
'parent' => 'hidden',
|
|
);
|
|
);
|
|
|
|
+ $compound = function (Options $options) {
|
|
|
|
+ return $options['parent'];
|
|
|
|
+ };
|
|
|
|
+ $resolver->setDefaults(array(
|
|
|
|
+ 'compound' => $compound,
|
|
|
|
+ ));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -54,7 +64,7 @@ class ModelReferenceType extends AbstractType
|
|
*/
|
|
*/
|
|
public function getParent()
|
|
public function getParent()
|
|
{
|
|
{
|
|
- return $this->parent;
|
|
|
|
|
|
+ return 'form';
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|