You are here

public function EntityHooks::onNodeUpdate in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x 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 124

Class

EntityHooks
Defines a class for entity hooks for the module.

Namespace

Drupal\entity_hierarchy_microsite

Code

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);
        }
      }
    }
  }
}