protected function AddHierarchy::getHierarchyFields in Search API 8
Finds all (potentially) hierarchical fields for this processor's index.
Fields are returned if:
- they point to an entity type; and
- that entity type contains a property referencing the same type of entity (so that a hierarchy could be built from that nested property).
Return value
string[][] An array containing all fields of the index for which hierarchical data might be retrievable. The keys are those field's IDs, the values are associative arrays containing the nested properties of those fields from which a hierarchy might be constructed, with the property paths as the keys and labels as the values.
1 call to AddHierarchy::getHierarchyFields()
- AddHierarchy::buildConfigurationForm in src/
Plugin/ search_api/ processor/ AddHierarchy.php - Form constructor.
File
- src/
Plugin/ search_api/ processor/ AddHierarchy.php, line 110
Class
- AddHierarchy
- Adds all ancestors' IDs to a hierarchical field.
Namespace
Drupal\search_api\Plugin\search_api\processorCode
protected function getHierarchyFields() {
if (!isset(static::$indexHierarchyFields[$this->index
->id()])) {
$field_options = [];
foreach ($this->index
->getFields() as $field_id => $field) {
try {
$definition = $field
->getDataDefinition();
} catch (SearchApiException $e) {
$vars = [
'%index' => $this->index
->label(),
];
watchdog_exception('search_api', $e, '%type while trying to retrieve a list of hierarchical fields on index %index: @message in %function (line %line of %file).', $vars);
continue;
}
if ($definition instanceof ComplexDataDefinitionInterface) {
$properties = $this
->getFieldsHelper()
->getNestedProperties($definition);
// The property might be an entity data definition itself.
$properties[''] = $definition;
foreach ($properties as $property) {
$property_label = $property
->getLabel();
$property = $this
->getFieldsHelper()
->getInnerProperty($property);
if ($property instanceof EntityDataDefinitionInterface) {
$options = static::findHierarchicalProperties($property, $property_label);
if ($options) {
$field_options += [
$field_id => [],
];
$field_options[$field_id] += $options;
}
}
}
}
}
static::$indexHierarchyFields[$this->index
->id()] = $field_options;
}
return static::$indexHierarchyFields[$this->index
->id()];
}