You are here

protected function PhotosImageSearch::indexPhotosImage in Album Photos 8.5

Same name and namespace in other branches
  1. 6.0.x src/Plugin/Search/PhotosImageSearch.php \Drupal\photos\Plugin\Search\PhotosImageSearch::indexPhotosImage()

Indexes a single node.

Parameters

\Drupal\photos\Entity\PhotosImage $photosImage: The photos_image to index.

Return value

array An array of words to update after indexing.

1 call to PhotosImageSearch::indexPhotosImage()
PhotosImageSearch::updateIndex in src/Plugin/Search/PhotosImageSearch.php
Updates the search index for this plugin.

File

src/Plugin/Search/PhotosImageSearch.php, line 514

Class

PhotosImageSearch
Handles searching for photos_image entities using the Search module index.

Namespace

Drupal\photos\Plugin\Search

Code

protected function indexPhotosImage(PhotosImage $photosImage) {
  $words = [];
  $languages = $photosImage
    ->getTranslationLanguages();
  $node_render = $this->entityTypeManager
    ->getViewBuilder('photos_image');
  foreach ($languages as $language) {
    $photosImage = $photosImage
      ->getTranslation($language
      ->getId());

    // Render the node.
    $build = $node_render
      ->view($photosImage, 'search_index', $language
      ->getId());
    unset($build['#theme']);

    // Add the title to text so it is searchable.
    $build['search_title'] = [
      '#prefix' => '<h1>',
      '#plain_text' => $photosImage
        ->label(),
      '#suffix' => '</h1>',
      '#weight' => -1000,
    ];
    $text = $this->renderer
      ->renderPlain($build);

    // Fetch extra data normally not visible.
    $extra = $this->moduleHandler
      ->invokeAll('node_update_index', [
      $photosImage,
    ]);
    foreach ($extra as $t) {
      $text .= $t;
    }

    // Update index, using search index "type" equal to the plugin ID.
    $words += $this->searchIndex
      ->index($this
      ->getPluginId(), $photosImage
      ->id(), $language
      ->getId(), $text, FALSE);
  }
  return $words;
}