public function EntityHooks::onNodeUpdate in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_microsite/src/EntityHooks.php \Drupal\entity_hierarchy_microsite\EntityHooks::onNodeUpdate()
React to node update.
Parameters
\Drupal\node\NodeInterface $node: Node update.
File
- modules/
entity_hierarchy_microsite/ src/ EntityHooks.php, line 138
Class
- EntityHooks
- Defines a class for entity hooks for the module.
Namespace
Drupal\entity_hierarchy_micrositeCode
public function onNodeUpdate(NodeInterface $node) {
$original = $node->original;
foreach ($this->parentCandidate
->getCandidateFields($node) as $field) {
if ($node
->hasField($field) && (!$node
->get($field)
->isEmpty() || !$original
->get($field)
->isEmpty() || ($node->{$field}->target_id !== $original->{$field}->target_id || $node->{$field}->weight !== $original->{$field}->weight))) {
if ($microsites = $this->childOfMicrositeLookup
->findMicrositesForNodeAndField($node, $field)) {
foreach ($microsites as $microsite) {
$this
->updateMenuForMicrosite($microsite);
}
continue;
}
if ($microsites = $this->childOfMicrositeLookup
->findMicrositesForNodeAndField($original, $field)) {
// This item is no longer in the microsite, so we need to trigger
// its removal.
$plugin_id = 'entity_hierarchy_microsite:' . $original
->uuid();
if ($this->menuLinkManager
->hasDefinition($plugin_id)) {
$this->menuLinkManager
->removeDefinition($plugin_id);
}
}
}
}
}