protected function FileSearch::indexFile in Search File Attachments 8
Indexes a single file.
Parameters
\Drupal\Core\Entity\EntityInterface $file: The file to index.
1 call to FileSearch::indexFile()
- FileSearch::updateIndex in src/
Plugin/ Search/ FileSearch.php - Updates the search index for this plugin.
File
- src/
Plugin/ Search/ FileSearch.php, line 298
Class
- FileSearch
- Executes a keyword search for files against {file_managed} database table.
Namespace
Drupal\search_file_attachments\Plugin\SearchCode
protected function indexFile(EntityInterface $file) {
if (!in_array($file
->getMimeType(), $this->includedMimetypes)) {
return;
}
$languages = $file
->getTranslationLanguages();
foreach ($languages as $language) {
$translation_options = array(
'langcode' => $language
->getId(),
);
$content = $this
->t('Filename', array(), $translation_options) . ': ' . $file
->getFilename() . ' - ' . $this
->t('Content', array(), $translation_options) . ': ';
// Extract the file content and add it to the drupal search index.
$extracted_content = SafeMarkup::checkPlain($this
->getFileContent($file));
$content .= $extracted_content;
// Update index, using search index "type" equal to the plugin ID.
search_index($this
->getPluginId(), $file
->id(), $language
->getId(), $content);
}
}