You are here

public function FilesExtractor::isFileIndexable in Search API attachments 9.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/processor/FilesExtractor.php \Drupal\search_api_attachments\Plugin\search_api\processor\FilesExtractor::isFileIndexable()

Check if the file is allowed to be indexed.

Parameters

object $file: A file object.

\Drupal\search_api\Item\ItemInterface $item: The item the file was referenced in.

string|null $field_name: The name of the field the file was referenced in, if applicable.

Return value

bool TRUE or FALSE

1 call to FilesExtractor::isFileIndexable()
FilesExtractor::addFieldValues in src/Plugin/search_api/processor/FilesExtractor.php

File

src/Plugin/search_api/processor/FilesExtractor.php, line 430

Class

FilesExtractor
Provides file fields processor.

Namespace

Drupal\search_api_attachments\Plugin\search_api\processor

Code

public function isFileIndexable($file, ItemInterface $item, $field_name = NULL) {

  // File should exist in disc.
  $indexable = file_exists($file
    ->getFileUri());
  if (!$indexable) {
    return FALSE;
  }

  // File should have a mime type that is allowed.
  $all_excluded_mimes = $this->extractFileValidator
    ->getExcludedMimes(NULL, $this->configuration['excluded_mimes']);
  $indexable = $indexable && !in_array($file
    ->getMimeType(), $all_excluded_mimes);
  if (!$indexable) {
    return FALSE;
  }

  // File permanent.
  $indexable = $indexable && $file
    ->isPermanent();
  if (!$indexable) {
    return FALSE;
  }

  // File shouldn't exceed configured file size.
  $max_filesize = $this->configuration['max_filesize'];
  $indexable = $indexable && $this->extractFileValidator
    ->isFileSizeAllowed($file, $max_filesize);
  if (!$indexable) {
    return FALSE;
  }

  // Whether a private file can be indexed or not.
  $excluded_private = $this->configuration['excluded_private'];
  $indexable = $indexable && $this->extractFileValidator
    ->isPrivateFileAllowed($file, $excluded_private);
  if (!$indexable) {
    return FALSE;
  }
  $result = $this->moduleHandler
    ->invokeAll('search_api_attachments_indexable', [
    $file,
    $item,
    $field_name,
  ]);
  $indexable = !in_array(FALSE, $result, TRUE);
  return $indexable;
}