You are here

protected function SearchApiFieldTrait::expandRequiredProperties in Search API 8

Expands the properties to retrieve for this field.

The properties are taken from this object's $retrievedFieldValues property, with all their ancestors also added to the array, with the ancestor properties always ordered before their descendants.

This will ensure, when dealing with these properties sequentially, that the parent object necessary to load the "child" property is always already loaded.

Return value

array[][] The properties to retrieve, keyed by their datasource ID and property path. The values are associative arrays with the following keys:

  • combined_property_path: The "combined property path" of the retrieved property.
  • dependents: An array containing the originally required properties that led to this property being required.
1 call to SearchApiFieldTrait::expandRequiredProperties()
SearchApiFieldTrait::preRender in src/Plugin/views/field/SearchApiFieldTrait.php
Runs before any fields are rendered.

File

src/Plugin/views/field/SearchApiFieldTrait.php, line 492

Class

SearchApiFieldTrait
Provides a trait to use for Search API Views field handlers.

Namespace

Drupal\search_api\Plugin\views\field

Code

protected function expandRequiredProperties() {
  $required_properties = [];
  foreach ($this->retrievedProperties as $datasource_id => $property_paths) {
    if ($datasource_id === '') {
      $datasource_id = NULL;
    }
    try {
      $index_properties = $this
        ->getIndex()
        ->getPropertyDefinitions($datasource_id);
    } catch (SearchApiException $e) {
      $this
        ->logException($e);
      $index_properties = [];
    }
    foreach ($property_paths as $property_path => $combined_property_path) {

      // In case the property is configurable, create a new, unique combined
      // property path for this field so adding multiple fields based on the
      // same property works correctly.
      if (($index_properties[$property_path] ?? NULL) instanceof ConfigurablePropertyInterface && !empty($this->definition['search_api field'])) {
        $new_path = $combined_property_path . '|' . $this->definition['search_api field'];
        $this->propertyReplacements[$combined_property_path] = $new_path;
        $combined_property_path = $new_path;
      }
      $paths_to_add = [
        NULL,
      ];
      $path_to_add = '';
      foreach (explode(':', $property_path) as $component) {
        $path_to_add .= ($path_to_add ? ':' : '') . $component;
        $paths_to_add[] = $path_to_add;
      }
      foreach ($paths_to_add as $path_to_add) {
        if (!isset($required_properties[$datasource_id][$path_to_add])) {
          $path = $this
            ->createCombinedPropertyPath($datasource_id, $path_to_add);
          if (isset($this->propertyReplacements[$path])) {
            $path = $this->propertyReplacements[$path];
          }
          $required_properties[$datasource_id][$path_to_add] = [
            'combined_property_path' => $path,
            'dependents' => [],
          ];
        }
        $required_properties[$datasource_id][$path_to_add]['dependents'][] = $combined_property_path;
      }
    }
  }
  return $required_properties;
}