You are here

protected function SearchApiAlterAddHierarchy::getHierarchicalFields in Search API 7

Finds all hierarchical fields for the current index.

Return value

array An array containing all hierarchical fields of the index, structured as an options array grouped by primary field.

2 calls to SearchApiAlterAddHierarchy::getHierarchicalFields()
SearchApiAlterAddHierarchy::configurationForm in includes/callback_add_hierarchy.inc
Implements SearchApiAlterCallbackInterface::configurationForm().
SearchApiAlterAddHierarchy::supportsIndex in includes/callback_add_hierarchy.inc
Overrides SearchApiAbstractAlterCallback::supportsIndex().

File

includes/callback_add_hierarchy.inc, line 165
Contains SearchApiAlterAddHierarchy.

Class

SearchApiAlterAddHierarchy
Adds all ancestors for hierarchical fields.

Code

protected function getHierarchicalFields() {
  if (!isset($this->field_options)) {
    $this->field_options = array();
    $wrapper = $this->index
      ->entityWrapper(NULL, FALSE);

    // Only entities can be indexed in hierarchies, as other properties don't
    // have IDs that we can extract and store.
    $entity_info = entity_get_info();
    foreach ($wrapper as $key1 => $child) {
      while (search_api_is_list_type($child
        ->type())) {
        $child = $child[0];
      }
      $info = $child
        ->info();
      $type = $child
        ->type();
      if (empty($entity_info[$type])) {
        continue;
      }
      foreach ($child as $key2 => $prop) {
        if (search_api_extract_inner_type($prop
          ->type()) == $type) {
          $prop_info = $prop
            ->info();
          $this->field_options[$info['label']]["{$key1}:{$key2}"] = $prop_info['label'];
        }
      }
    }
  }
  return $this->field_options;
}