public function SearchApiAlterAddHierarchy::extractHierarchy in Search API 7
Extracts a hierarchy from a metadata wrapper by modifying $values.
1 call to SearchApiAlterAddHierarchy::extractHierarchy()
- SearchApiAlterAddHierarchy::alterItems in includes/
callback_add_hierarchy.inc - Alter items before indexing.
File
- includes/
callback_add_hierarchy.inc, line 195 - Contains SearchApiAlterAddHierarchy.
Class
- SearchApiAlterAddHierarchy
- Adds all ancestors for hierarchical fields.
Code
public function extractHierarchy(EntityMetadataWrapper $wrapper, $property, array &$values) {
if (search_api_is_list_type($wrapper
->type())) {
foreach ($wrapper as $w) {
$this
->extractHierarchy($w, $property, $values);
}
return;
}
try {
$v = $wrapper
->value(array(
'identifier' => TRUE,
));
if ($v && !isset($values[$v])) {
$values[$v] = $v;
if (isset($wrapper->{$property}) && $wrapper
->value() && $wrapper->{$property}
->value()) {
$this
->extractHierarchy($wrapper->{$property}, $property, $values);
}
}
} catch (EntityMetadataWrapperException $e) {
// Some properties like entity_metadata_book_get_properties() throw
// exceptions, so we catch them here and ignore the property.
}
}