You are here

protected function FileSearch::getFileContent in Search File Attachments 8

Extract the content of the given file.

Parameters

\Drupal\Core\Entity\EntityInterface $file: The file that should be indexed.

Return value

string A string with th extracted content from the file.

1 call to FileSearch::getFileContent()
FileSearch::indexFile in src/Plugin/Search/FileSearch.php
Indexes a single file.

File

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

Class

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

Namespace

Drupal\search_file_attachments\Plugin\Search

Code

protected function getFileContent(EntityInterface $file) {
  $file_path = file_create_url($file
    ->getFileUri());
  $image_mimetypes = array(
    'image/jpeg',
    'image/jpg',
    'image/tiff',
  );
  if ($file
    ->getMimeType() == 'text/plain' || $file
    ->getMimeType() == 'text/x-diff') {
    $content = $this
      ->extractContentSimple($file, $file_path);
  }
  elseif (in_array($file
    ->getMimeType(), $image_mimetypes)) {
    $content = $this
      ->extractContentExif($file, $file_path);
  }
  else {
    $content = $this
      ->extractContentTika($file, $file_path);
  }
  return $content;
}