Problem description
I need to define object-related field (like sonata_type_model_list) inside sonata_type_immutable_array form type definition:
$formMapper->add('options', 'sonata_type_immutable_array', array(
'keys' => array(
array('linkName', 'text', array()),
array('linkPath', 'sonata_type_model_list',
array(
'model_manager' => $linkAdmin->getModelManager(),
'class' => $linkAdmin->getClass(),
)
)
)
)
This is not working, here is error message:
Impossible to access an attribute ("associationadmin") on a NULL variable ("") in SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig at line 60
What I found about this problem
I tryed to find any information about using sonata_type_model_list inside sonata_type_immutable_array, but there is very little information. This (https://github.com/a2lix/TranslationFormBundle/issues/155) topic helped me a bit, but doing all in the same manner I've got another error:
Impossible to invoke a method ("id") on a NULL variable ("") in SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig at line 60
So I totally failed in uderstanding what I have to do.
My context
-- I have Doctrine ORM Mapped class called CmsLink, it defines object to which 'linkPath' field relates.
-- I have admin class for CmsLink class, it has very basic configuration:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('technicalAlias')
->add('url')
;
}
-- I have Doctrine ORM Mapped class called CmsMenuItem, it defines object and 'options' filed which persists data managed by sonata_type_immutable_array form type, field type is json_array:
/**
* @var string
*
* @ORM\Column(name="options", type="json_array", nullable=true)
*/
private $options;
-- And finally I have admin class for CmsMenuItem class, here is the key code piece:
$linkAdmin = $this->configurationPool->getAdminByClass("Argon\\CMSBundle\\Entity\\CmsLink");
$formMapper
->add('options', 'sonata_type_immutable_array',
array(
'keys' => array(
array('linkName', 'text', array()),
array('linkPath', 'sonata_type_model_list',
array(
'model_manager' => $linkAdmin->getModelManager(),
'class' => $linkAdmin->getClass(),
)
),
array('description', 'textarea', array()),
array('image', 'sonata_media_type',
array(
'provider' => 'sonata.media.provider.image',
'context' => 'pages_static',
'required'=>false,
)
)
)
)
);
Question goals
- Find out what I need to do to bring life into this idea?
- Get general information and understanding abot how to include object-related field types into sonata_type_immutable_array