1
votes

In my document I have a field that I want to store the related nodes and I defined it like this:

/**
 * @PHPCRODM\ReferenceMany(targetDocument="Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page", strategy="hard")
*/
protected $related_guides;

I added the related nodes using the document manager and I can see them and created links in my twig file. The problem that I have is allowing the admin to add or delete the related nodes in the sonata admin.

When I used ORM I used 'sonata_type_collection' but it seems it doesn't work in ODM. I got this error:

INVALID MODE : s537a4d1c263c0_related_guides - type : sonata_type_collection - mapping : 8

sonata_type_model_list only works for ReferenceOne relations and for ReferenceMany I got this error:

The class 'Doctrine\ODM\PHPCR\ReferenceManyCollection' was not found in the chain configured namespaces Doctrine\ODM\PHPCR\Document, Sandbox\MainBundle\Document, Vectorworks\Bundle\CmsBundle\Document, Symfony\Component\Routing, Symfony\Cmf\Bundle\RoutingBundle\Model, Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\MenuBundle\Model, Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\ContentBundle\Model, Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\BlockBundle\Model, Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\SeoBundle\Model, Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr, Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr

Is there any way to get this functionality out of Sonata Admin? BTW my fields is the type of Doctrine\ODM\PHPCR\ReferenceManyCollection to support the @ReferenceMany relation.

2
The exception looks like doctrine is trying to treat ReferenceManyCollection as a document class that would itself be mapped. that makes no sense. the sonata_type_collection is indeed broken in phpcr-odm: github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/… - hopefully somebody will take the time to dig into that one day. what does work is embedding with the sonata_type_collection, for example github.com/symfony-cmf/BlockBundle/blob/master/Admin/Imagine/…dbu
Thanks! I'll look into it. At least I know I'm not doing it wrong.MKoosej

2 Answers

0
votes

For ReferenceMany try using "phpcr_document":

$formPapper->add('related_guides', 'phpcr_document', 
    array(
        'property' => 'title',
        'class'    => 'Acme\DemoBundle\Document\TargetClass',
        'multiple' => true,
   ))
->end();
0
votes

The above code seems to be a little old: for Symfony 3.3, use the following code:

use Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType;
...
$formPapper->add('related_guides', DocumentType::class, 
        array(
            'choice_label' => 'title', // where TargetClass::getTitle()
            'class'    => 'Acme\DemoBundle\Document\TargetClass',
            'multiple' => true,
       ))
    ->end();