diff --git a/src/Plugin/search_api/processor/AddHierarchy.php b/src/Plugin/search_api/processor/AddHierarchy.php index b6f4bb8..9e73d14 100644 --- a/src/Plugin/search_api/processor/AddHierarchy.php +++ b/src/Plugin/search_api/processor/AddHierarchy.php @@ -77,11 +77,12 @@ public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_man * {@inheritdoc} */ public static function supportsIndex(IndexInterface $index) { - return (bool) static::getHierarchyFields($index); + $processor = new static(array('#index' => $index), 'hierarchy', array()); + return (bool) $processor->getHierarchyFields(); } /** - * Finds all (potentially) hierarchical fields for the given index. + * Finds all (potentially) hierarchical fields for this processor's index. * * Fields are returned if: * - they point to an entity type; and @@ -89,9 +90,6 @@ public static function supportsIndex(IndexInterface $index) { * (so that a hierarchy could be built from that nested property); or * - that entity type has the same field. * - * @param \Drupal\search_api\IndexInterface $index - * The index for which hierarchical fields should be found. - * * @return 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 @@ -99,10 +97,10 @@ public static function supportsIndex(IndexInterface $index) { * which a hierarchy might be constructed, with the property paths as the * keys and labels as the values. */ - protected static function getHierarchyFields(IndexInterface $index) { + protected function getHierarchyFields() { $field_options = array(); - foreach ($index->getFields() as $field_id => $field) { + foreach ($this->index->getFields() as $field_id => $field) { $definition = $field->getDataDefinition(); if ($definition instanceof ComplexDataDefinitionInterface) { $properties = $definition->getPropertyDefinitions(); @@ -110,9 +108,7 @@ protected static function getHierarchyFields(IndexInterface $index) { $properties[''] = $definition; foreach ($properties as $property) { $property_label = $property->getLabel(); - $property = \Drupal::getContainer() - ->get('search_api.fields_helper') - ->getInnerProperty($property); + $property = $this->getFieldsHelper()->getInnerProperty($property); if ($property instanceof EntityDataDefinitionInterface) { $options = self::findHierarchicalProperties($property, $property_label); if ($options) { @@ -152,15 +148,14 @@ protected static function getHierarchyFields(IndexInterface $index) { * property's entity type ID and the nested properties identifier, * concatenated with a dash (-). */ - protected static function findHierarchicalProperties(EntityDataDefinitionInterface $property, $property_label) { + protected function findHierarchicalProperties(EntityDataDefinitionInterface $property, $property_label) { $entity_type_id = $property->getEntityTypeId(); $options = array(); - $fields_helper = \Drupal::getContainer()->get('search_api.fields_helper'); // Check properties for potential hierarchy. foreach ($property->getPropertyDefinitions() as $name_2 => $property_2) { $property_2_label = $property_2->getLabel(); - $property_2 = $fields_helper->getInnerProperty($property_2); + $property_2 = $this->getFieldsHelper()->getInnerProperty($property_2); if ($property_2 instanceof EntityDataDefinitionInterface) { if ($property_2->getEntityTypeId() == $entity_type_id) { $options["$entity_type_id-$name_2"] = Html::escape($property_label . ' » ' . $property_2_label); @@ -168,7 +163,7 @@ protected static function findHierarchicalProperties(EntityDataDefinitionInterfa } elseif ($property_2 instanceof ComplexDataDefinitionInterface) { foreach ($property_2->getPropertyDefinitions() as $property_3) { - $property_3 = $fields_helper->getInnerProperty($property_3); + $property_3 = $this->getFieldsHelper()->getInnerProperty($property_3); if ($property_3 instanceof EntityDataDefinitionInterface) { if ($property_3->getEntityTypeId() == $entity_type_id) { $options["$entity_type_id-$name_2"] = Html::escape($property_label . ' » ' . $property_2_label); @@ -196,7 +191,7 @@ public function defaultConfiguration() { public function buildConfigurationForm(array $form, FormStateInterface $formState) { $form['#description'] = $this->t('Select the fields to which hierarchical data should be added.'); - foreach (static::getHierarchyFields($this->index) as $field_id => $options) { + foreach ($this->getHierarchyFields() as $field_id => $options) { $enabled = !empty($this->configuration['fields'][$field_id]); $form['fields'][$field_id]['status'] = array( '#type' => 'checkbox',