You are here

private function SearchStyleguide::searchNodePrepare in Style Guide 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Styleguide/SearchStyleguide.php \Drupal\styleguide\Plugin\Styleguide\SearchStyleguide::searchNodePrepare()

Helper method to prepare a fake node for the search.

Parameters

int $i: Search row number.

Return value

array Returns a prepared node for the node search sample.

1 call to SearchStyleguide::searchNodePrepare()
SearchStyleguide::searchResults in src/Plugin/Styleguide/SearchStyleguide.php
Generate fake search results.

File

src/Plugin/Styleguide/SearchStyleguide.php, line 243

Class

SearchStyleguide
Search Styleguide items implementation.

Namespace

Drupal\styleguide\Plugin\Styleguide

Code

private function searchNodePrepare($i) {

  // Render a fake node.
  $node = Node::create([
    'type' => 'article',
    'title' => "Title {$i}",
    'body' => $this->generator
      ->words(20),
    'in_preview' => TRUE,
  ]);
  $build = $this->entityTypeManager
    ->getViewBuilder('node')
    ->view($node, 'search_result');
  unset($build['#theme']);
  $rendered = $this->renderer
    ->renderPlain($build);
  return [
    'title' => $node
      ->label(),
    'node' => $node,
    'extra' => $this->moduleHandler
      ->invokeAll('node_search_result', [
      $node,
    ]),
    'snippet' => search_excerpt('title', $rendered),
    'date' => time(),
    'user' => [
      '#theme' => 'username',
      '#account' => $this->currentUser,
    ],
  ];
}