You are here

function _auto_index_node_index in Auto Index 8

Check to see whether a node ID has been acted on, and if not then we can call on the search plugin, to index the content.

Parameters

unknown $node_id.:

3 calls to _auto_index_node_index()
auto_index_node_insert in ./auto_index.module
Implementation of hook_ENTITY_TYPE_insert().
auto_index_node_update in ./auto_index.module
Implementation of hook_ENTITY_TYPE_update().
_auto_index_comment_index in ./auto_index.module
Update the node attached to a comment.

File

./auto_index.module, line 91
Auto-index: Automatically indexes node content on update.

Code

function _auto_index_node_index($node) {

  // Load if numeric (node_id)
  if (is_numeric($node)) {
    $node = \Drupal::entityManager()
      ->getStorage('node')
      ->load($node);
    if (!$node) {
      return;
    }
  }

  // Static variable to keep track of any node ids already indexed.
  static $indexed_nodes = array();

  // Check if the node has already been acted upon.
  if (array_search($node
    ->id(), $indexed_nodes) === FALSE) {

    // Load the module plugin registry and look for automatic indexing in the config.
    $search_page_repository = \Drupal::service('search.search_page_repository');
    foreach ($search_page_repository
      ->getIndexableSearchPages() as $entity) {
      $plugin = $entity
        ->getPlugin();
      $conf = $plugin
        ->getConfiguration();
      if ($conf['automatic_indexing']) {
        $plugin
          ->indexSingleNode($node);
      }
    }

    // Append to array to ensure node only indexed once per action.
    $indexed_nodes[] = $node
      ->id();
  }
}