You are here

public function Snippet::render in Views search snippet 1.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/Snippet.php \Drupal\views_search_snippet\Plugin\views\field\Snippet::render()
  2. 2.x src/Plugin/views/field/Snippet.php \Drupal\views_search_snippet\Plugin\views\field\Snippet::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides NumericField::render

File

src/Plugin/views/field/Snippet.php, line 48

Class

Snippet
Field handler for search snippet.

Namespace

Drupal\views_search_snippet\Plugin\views\field

Code

public function render(ResultRow $values) {

  // Only render if we exist.
  if (isset($this->searchFilterPresent)) {
    $node_renderer = \Drupal::entityManager()
      ->getViewBuilder('node');
    $node = $this
      ->getEntity($values);

    //Todo:langcode

    //$langcode = $this->getValue($values);

    //Todo:langcode

    // $node = $node->getTranslation($langcode);
    $build = $node_renderer
      ->view($node, 'search_result');
    unset($build['#theme']);
    $node_rendered = drupal_render($build);

    // Fetch comment count for snippet.

    //Todo:langcode
    $keys = $this->view
      ->getExposedInput()['keys'];
    $output = $node_rendered
      ->__toString();
    $snippet = search_excerpt($keys, $output);
    return $snippet;
  }
}