You are here

protected function SearchService::renderResults in Fast Autocomplete 8

Renders the results in the configured view mode.

Parameters

\Drupal\fac\FacConfigInterface $fac_config: The FacConfig entity.

array $search_results: The results to render.

string $langcode: The language code.

Return value

array The array of rendered items.

1 call to SearchService::renderResults()
SearchService::getResults in src/SearchService.php
Return the results based on the given key.

File

src/SearchService.php, line 76

Class

SearchService
Class SearchService.

Namespace

Drupal\fac

Code

protected function renderResults(FacConfigInterface $fac_config, array $search_results, $langcode) {
  $results = [];
  foreach ($search_results as $search_result) {
    try {
      $entity = $this->entityTypeManager
        ->getStorage($search_result['entity_type'])
        ->load($search_result['entity_id']);
    } catch (InvalidPluginDefinitionException $e) {
      return [];
    }
    $view_builder = $this->entityTypeManager
      ->getViewBuilder($search_result['entity_type']);
    $view_modes = $fac_config
      ->getViewModes();
    $build = $view_builder
      ->view($entity, $view_modes[$search_result['entity_type']], $langcode);
    $results[] = render($build);
  }
  return $results;
}