function _views_menu_reference_get_link_path_parents_hierarchy in Views Menu Reference 7
Private variant of views_menu_reference_get_link_path_parents_hierarchy(). Contains the true logic behind the caching.
Parameters
string $link_path:
Return value
array
1 call to _views_menu_reference_get_link_path_parents_hierarchy()
- views_menu_reference_get_link_path_parents_hierarchy in ./
views_menu_reference.module - Returns the <$link_path>'s parent menu hierarchy. It describes the mlids in each depth that may be direct (0) or indirect (1..*) parent. The hierarchy is indexed by the depth and may contain the tree items from more than one menu item,…
File
- ./
views_menu_reference.module, line 58 - views_menu_reference module core implementations.
Code
function _views_menu_reference_get_link_path_parents_hierarchy($link_path) {
// Use the alias and source pathes because a link can directly link both.
$link_pathes = array(
$link_path => $link_path,
);
$link_path_alias = drupal_lookup_path('alias', $link_path);
if ($link_path_alias !== FALSE) {
$link_pathes[$link_path_alias] = $link_path_alias;
}
$link_path_source = drupal_lookup_path('source', $link_path);
if ($link_path_source !== FALSE) {
$link_pathes[$link_path_source] = $link_path_source;
}
// Special case: Add <front> placeholder if the link path is the frontpage!
if ($link_path == variable_get('site_frontpage', 'node')) {
$link_pathes['<front>'] = '<front>';
}
if (empty($link_pathes)) {
// No matching results in the menu tree at all.
return array();
}
// Get the <$link_path> menu items and their properties we need.
$query = db_select('menu_links', 'ml');
$query
->fields('ml', array(
'mlid',
'depth',
'p1',
'p2',
'p3',
'p4',
'p5',
'p6',
'p7',
'p8',
'p9',
));
$query
->condition('link_path', $link_pathes, 'IN');
$result = $query
->execute();
$parents_hierarchy = array();
foreach ($result as $record) {
// Process all pX Elements (not including sub menu entries!)
$depth = $record->depth;
$i = 0;
while ($depth > 0) {
$parent_field = 'p' . $depth;
$parent_field_value = $record->{$parent_field};
if (!empty($parent_field_value)) {
// We index the fields by their value so we ensure that no item is added twice with high performance.
// This truely is nothing else then $parents_hierarchy[$i][] PLUS unique.
$parents_hierarchy[$i][$parent_field_value] = $parent_field_value;
}
$depth--;
$i++;
}
// Process all pX+ Elements (including sub menu entries!)
$depth = $record->depth;
$i = 1;
while ($i <= $depth) {
$parent_field = 'p' . $i;
$parent_field_value = $record->{$parent_field};
if (!empty($parent_field_value)) {
// We index the fields by their value so we ensure that no item is added twice with high performance.
// This truely is nothing else then $parents_hierarchy[$i][] PLUS unique.
$parents_hierarchy[$i . '+'][$parent_field_value] = $parent_field_value;
}
$i++;
}
}
return $parents_hierarchy;
}