ParentEntityRevisionUpdater.php in Entity Reference Hierarchy 8.2
File
src/Storage/ParentEntityRevisionUpdater.php
View source
<?php
namespace Drupal\entity_hierarchy\Storage;
use Drupal\Core\Entity\ContentEntityInterface;
class ParentEntityRevisionUpdater extends ParentEntityReactionBase {
public function moveChildren(ContentEntityInterface $oldRevision, ContentEntityInterface $newRevision) {
if (!$newRevision
->isDefaultRevision()) {
return;
}
if ($newRevision
->getRevisionId() == $oldRevision
->getRevisionId()) {
return;
}
if (!($fields = $this->parentCandidate
->getCandidateFields($newRevision))) {
return;
}
$oldNodeKey = $this->nodeKeyFactory
->fromEntity($oldRevision);
$newNodeKey = $this->nodeKeyFactory
->fromEntity($newRevision);
foreach ($fields as $field_name) {
$this
->lockTree($field_name, $newRevision
->getEntityTypeId());
$storage = $this->nestedSetStorageFactory
->get($field_name, $newRevision
->getEntityTypeId());
if (!($newParent = $storage
->getNode($newNodeKey))) {
$newParent = $storage
->addRootNode($newNodeKey);
}
if ($storage
->findChildren($oldNodeKey)) {
$storage
->adoptChildren($storage
->getNode($oldNodeKey), $newParent);
}
$this
->releaseLock($field_name, $newRevision
->getEntityTypeId());
}
}
}