function forum_node_update

forum_node_update(EntityInterface $node)

Implements hook_ENTITY_TYPE_update() for node entities.

File

core/modules/forum/forum.module, line 170
Provides discussion forums.

Code

function forum_node_update(EntityInterface $node) {
  if (\Drupal::service('forum_manager')->checkNodeType($node)) {
    // If this is not a new revision and does exist, update the forum record,
    // otherwise insert a new one.
    /** @var \Drupal\forum\ForumIndexStorageInterface $forum_index_storage */
    $forum_index_storage = \Drupal::service('forum.index_storage');
    if ($node->getRevisionId() == $node->original->getRevisionId() && $forum_index_storage->getOriginalTermId($node)) {
      if (!empty($node->forum_tid)) {
        $forum_index_storage->update($node);
      }
      // The node is removed from the forum.
      else {
        $forum_index_storage->delete($node);
      }
    }
    else {
      if (!empty($node->forum_tid)) {
        $forum_index_storage->create($node);
      }
    }
    // If the node has a shadow forum topic, update the record for this
    // revision.
    if (!empty($node->shadow)) {
      $forum_index_storage->deleteRevision($node);
      $forum_index_storage->create($node);
    }

    // If the node is published, update the forum index.
    if ($node->isPublished()) {
      $forum_index_storage->deleteIndex($node);
      $forum_index_storage->createIndex($node);
    }
    // When a forum node is unpublished, remove it from the forum_index table.
    else {
      $forum_index_storage->deleteIndex($node);
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!forum!forum.module/function/forum_node_update/8.1.x