You are here

protected function ProcessorPluginBase::findField in Search API 8

Finds a certain field in the index.

Parameters

string|null $datasource_id: The ID of the field's datasource, or NULL for a datasource-independent field.

string $property_path: The field's property path on the datasource.

string|null $type: (optional) If set, only return a field if it has this type.

Return value

\Drupal\search_api\Item\FieldInterface|null A field on the index with the desired properties, or NULL if none could be found.

3 calls to ProcessorPluginBase::findField()
ContentAccess::addNodeAccess in src/Plugin/search_api/processor/ContentAccess.php
Adds a node access filter to a search query, if applicable.
ProcessorPluginBase::ensureField in src/Processor/ProcessorPluginBase.php
Ensures that a field with certain properties is indexed on the index.
RoleAccess::preprocessSearchQuery in src/Plugin/search_api/processor/RoleAccess.php
Preprocesses a search query.

File

src/Processor/ProcessorPluginBase.php, line 251

Class

ProcessorPluginBase
Defines a base class from which other processors may extend.

Namespace

Drupal\search_api\Processor

Code

protected function findField($datasource_id, $property_path, $type = NULL) {
  foreach ($this->index
    ->getFieldsByDatasource($datasource_id) as $field) {
    if ($field
      ->getPropertyPath() === $property_path) {
      if ($type === NULL || $field
        ->getType() === $type) {
        return $field;
      }
    }
  }
  return NULL;
}