You are here

protected function FileSearch::prepareResults in Search File Attachments 8

Prepares search results for rendering.

Parameters

\Drupal\Core\Database\StatementInterface $found: Results found from a successful search query execute() method.

Return value

array Array of search result item render arrays (empty array if no results).

1 call to FileSearch::prepareResults()
FileSearch::execute in src/Plugin/Search/FileSearch.php
Executes the search.

File

src/Plugin/Search/FileSearch.php, line 222

Class

FileSearch
Executes a keyword search for files against {file_managed} database table.

Namespace

Drupal\search_file_attachments\Plugin\Search

Code

protected function prepareResults(StatementInterface $found) {
  $results = array();
  $file_storage = $this->entityManager
    ->getStorage('file');
  $keys = $this->keywords;
  foreach ($found as $item) {
    $file = $file_storage
      ->load($item->sid)
      ->getTranslation($item->langcode);
    $result = array(
      'link' => file_create_url($file
        ->getFileUri()),
      'title' => Html::escape($file
        ->getFilename()),
      'snippet' => search_excerpt($keys, $item->data, $item->langcode),
      'langcode' => $file
        ->language()
        ->getId(),
    );
    $results[] = $result;
  }
  return $results;
}