You are here

protected function SearchApiSolrBackend::isHierarchicalField in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isHierarchicalField()
  2. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isHierarchicalField()
  3. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isHierarchicalField()

Checks if a field is (potentially) hierarchical.

Fields are (potentially) hierarchical 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

bool TRUE if the field is hierarchical, FALSE otherwise.

Throws

\Drupal\search_api\SearchApiException

See also

\Drupal\search_api\Plugin\search_api\processor\AddHierarchy::getHierarchyFields()

1 call to SearchApiSolrBackend::isHierarchicalField()
SearchApiSolrBackend::formatSolrFieldNames in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Returns a language-specific mapping from Drupal to Solr field names.

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 2361

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function isHierarchicalField(FieldInterface $field) {
  $definition = $field
    ->getDataDefinition();
  if ($definition instanceof ComplexDataDefinitionInterface) {
    $properties = $this->fieldsHelper
      ->getNestedProperties($definition);

    // The property might be an entity data definition itself.
    $properties[''] = $definition;
    foreach ($properties as $property) {
      $property = $this->fieldsHelper
        ->getInnerProperty($property);
      if ($property instanceof EntityDataDefinitionInterface) {
        if ($this
          ->hasHierarchicalProperties($property)) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}