I am using SonataAdminBundle and in the form I want to display some mapped information. My main object Skin is mapped with CmsElemnt, in witch the content is saved. I need to acces it in the form to be able to update it.
I have this mapped information:
Skin.php
/**
* @ORM\OneToMany(targetEntity="CmsElement", mappedBy="content")
*/
private $navbar;
CmsElement.php
/**
* @ORM\ManyToOne(targetEntity="Skin", inversedBy="navbar")
* @ORM\JoinColumn(name="page_id", referencedColumnName="id")
*/
private $content;
I tried using the symfony dcumentation Here:
http://symfony.com/doc/current/book/forms.html#embedding-a-single-object
So I created a service to load the CmsElement information:
class SkinElementType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('content', 'textarea');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Mp\ShopBundle\Entity\CmsElement',
));
}
public function getName()
{
return 'skin_element_type_cms';
}
}
Registered it:
skin_element_type_cms:
class: Mp\ShopBundle\Form\Type\SkinElementType
tags:
- { name: form.type }
Now in the skin admin I do this:
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
// ->add('id', 'hidden')
->add('name')
->add('status', null, array('required' => false))
->add('skin_element_type_cms', new CmsElement(), array(
'required' => false,
'attr' => array('cols' => '8', 'rows' => '8')))
}
I get this error:
Please define a type for field `skin_element_type_cms` in `Mp\ShopBundle\Admin\SkinAdmin`