Closed dantleech closed 11 years ago
/cc @sjopet
Ok I found the problem and its a simple fix. This also means we don't have to set the admin_code attribute on sonata_type_collection fields manually any more.
The problem is caused by a naming conflict in the association mappings. The associationMapping of the sonata_type_collection field looks like this:
array(
'fieldName' => 'menus',
'referencedBy' => 'weakContent',
'referringDocument' => 'Symfony\Cmf\Bundle\MenuBundle\Document\MenuNode',
'cascade' => 1,
'sourceDocument' => 'Symfony\Cmf\Bundle\ContentBundle\Document\MultilangStaticContent',
'type' => 'referrers',
'strategy' => 'weak',
'declared' => 'Symfony\Cmf\Bundle\ContentBundle\Document\StaticContent'
);
The admin responsable for the target document is attached to the fieldDescription based on the getTargetEntity function in Sonata/DoctrinePHPCRAdminBundle/Admin/FieldDescription.php
public function getTargetEntity()
{
if (isset($this->associationMapping['targetDocument'])) {
return $this->associationMapping['targetDocument'];
}
return null;
}
and it seems the key 'targetDocument' is not used anymore. Changing it to 'referringDocument' will fix the problem.
This is a collection based on a referrers relation. I'm not sure what the associationMapping of a referenceOne or referenceMany looks like so could not do the pr yet.
because targetDocument attribute is used for referenceOne etc just adding a condition for referringDocument should do.
PR merged. Issue can be closed
If the
type_collection
field has mixed referrers it will crash. See the MultilangStaticContent admin in the cmf-sandbox to reproduce.