class ParentEntityRevisionUpdater in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Storage/ParentEntityRevisionUpdater.php \Drupal\entity_hierarchy\Storage\ParentEntityRevisionUpdater
Defines a class for handling a parent entity is updated to a new revision.
Hierarchy
- class \Drupal\entity_hierarchy\Storage\ParentEntityReactionBase implements ContainerInjectionInterface uses TreeLockTrait
- class \Drupal\entity_hierarchy\Storage\ParentEntityRevisionUpdater
Expanded class hierarchy of ParentEntityRevisionUpdater
1 file declares its use of ParentEntityRevisionUpdater
- entity_hierarchy.module in ./
entity_hierarchy.module - A module to make entities hierarchical.
File
- src/
Storage/ ParentEntityRevisionUpdater.php, line 10
Namespace
Drupal\entity_hierarchy\StorageView source
class ParentEntityRevisionUpdater extends ParentEntityReactionBase {
/**
* Move children from old revision to new revision.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $oldRevision
* Old revision.
* @param \Drupal\Core\Entity\ContentEntityInterface $newRevision
* New revision.
*/
public function moveChildren(ContentEntityInterface $oldRevision, ContentEntityInterface $newRevision) {
if (!$newRevision
->isDefaultRevision()) {
// We don't move children to a non-default revision.
return;
}
if ($newRevision
->getRevisionId() == $oldRevision
->getRevisionId()) {
// We don't move anything if the revision isn't changing.
return;
}
if (!($fields = $this->parentCandidate
->getCandidateFields($newRevision))) {
// There are no fields that could point to this entity.
return;
}
$oldNodeKey = $this->nodeKeyFactory
->fromEntity($oldRevision);
$newNodeKey = $this->nodeKeyFactory
->fromEntity($newRevision);
foreach ($fields as $field_name) {
$this
->lockTree($field_name, $newRevision
->getEntityTypeId());
/** @var \Pnx\NestedSet\NestedSetInterface $storage */
$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());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ParentEntityReactionBase:: |
protected | property | Nested set storage. | |
ParentEntityReactionBase:: |
protected | property | Node key factory. | |
ParentEntityReactionBase:: |
protected | property | Parent candidate interface. | |
ParentEntityReactionBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
1 |
ParentEntityReactionBase:: |
public | function | Constructs a new ParentEntityRevisionUpdater object. | 1 |
ParentEntityRevisionUpdater:: |
public | function | Move children from old revision to new revision. | |
TreeLockTrait:: |
protected | property | Lock backend. | |
TreeLockTrait:: |
protected | function | Gets lock name. | |
TreeLockTrait:: |
protected | function | Gets lock backend. | |
TreeLockTrait:: |
protected | function | Locks tree. | |
TreeLockTrait:: |
protected | function | Releases lock. | |
TreeLockTrait:: |
public | function | Sets lock backend. |