Search code examples
sonata-adminsymfony-sonatadoctrine-odmsymfony-cmfdoctrine-phpcr

Sonata Doctrine Phpcr Admin Bundle: Change parent of node


I have problem with changing parent of document inside sonata admin.

My document has property like this:

 /**
 * @PHPCRODM\Children(filter="teaserimage*", cascade="persist")
 * @var Image[]
 */
protected $teaserImages;
....
/**
 * @Validation\PhpcrImage(maxWidth="1500", maxHeight="844", minWidth="600", minHeight="338", minRatio="1.77", maxRatio="1.78", nullable=false)
 *
 * @return Image|null
 */
public function getTeaserImage()
{
   return $this->getLocalizedImage($this->teaserImages, 'teaserimage');
}

/**
 * @param Image $image
 */
public function setTeaserImage($image)
{
    $this->teaserImages->add(
        self::setupImage($image, $this->getLocalizedImageNodeName('teaserimage'), $this->getTeaserImage())
    );
}

When i tried to change parent of any article document i got error like

The server returned a "500 Internal Server Error".

The Id is immutable (/cms/content/blog/blog-post-for-12th-october/teaserimage_de.jpg !== /cms/content/blog/blog-post-for-12th-october). Please use DocumentManager::move to move the document: blog post for 12th October (/cms/content/blog/blog-post-for-12th-october)

Although this error occurs, my document has been moved to the right place with all subdocument.

this is how my document looks like https://gist.github.com/milosnovi/a83f400c8ff06b4de6dd96e1f149a8dd


Solution

  • Check your preUpdated, prePersists methods. You shouldn't flush object in these methods while the change is a parent change.