Commit 48c3ac1c authored by anon's avatar anon

Added #1914236 by emattias, anon: Show reverse menu trail if result has menu item(s).

parent 45ecd8d6
......@@ -106,6 +106,10 @@ function linkit_theme($existing, $type, $theme, $path) {
'variables' => array(),
'file' => 'linkit.theme.inc'
),
'linkit_reverse_menu_trail' => array(
'variables' => array('menu_trail' => NULL, 'separator' => ' « '),
'file' => 'linkit.theme.inc'
)
);
}
......
......@@ -135,4 +135,20 @@ function _linkit_theme_profile_form_table($variables, $type) {
}
return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'linkit-' . $type), 'sticky' => FALSE));
}
/**
* Returns HTML for a reverse menu trail. (Based on theme_breadcrumb)
*
* @param $variables
* An associative array containing:
* - reverse_menu_trail: An array containing the menu trail item titles.
*/
function theme_linkit_reverse_menu_trail($variables) {
$menu_trail = $variables['reverse_menu_trail'];
if (!empty($menu_trail)) {
$output = '<p>' . implode($variables['separator'], $menu_trail) . '</p>';
return $output;
}
}
\ No newline at end of file
......@@ -105,9 +105,57 @@ class LinkitPluginEntity extends LinkitPlugin {
$description = token_replace(check_plain($this->conf['result_description']), array(
$this->plugin['entity_type'] => $data,
), array('clear' => TRUE));
if (isset($this->conf['reverse_menu_trail']) && $this->conf['reverse_menu_trail']) {
$description .= $this->buildReverseMenuTrail($data);
}
return $description;
}
/**
* Builds a reverse menu trail for the entity.
*
* @param object $data
* An entity object.
*/
function buildReverseMenuTrail($data) {
$vars = array();
$output = '';
$uri = entity_uri($this->plugin['entity_type'], $data);
if (isset($uri['path'])) {
$menu_link_fields = array('link_title', 'link_path', 'plid', 'menu_name');
$menu_items = db_select('menu_links', 'ml')
->fields('ml', $menu_link_fields)
->condition('link_path', $uri['path'])
->execute()->fetchAll(PDO::FETCH_ASSOC);
foreach ($menu_items as $menu_item) {
$vars['reverse_menu_trail'] = array();
while ($menu_item['plid']) {
$menu_item = db_select('menu_links', 'ml')
->fields('ml', $menu_link_fields)
->condition('mlid', $menu_item['plid'])
->execute()
->fetchAssoc();
if (isset($menu_item['link_title'])) {
$vars['reverse_menu_trail'][] = $menu_item['link_title'];
}
}
$output .= !empty($vars['reverse_menu_trail']) ? theme('linkit_reverse_menu_trail', $vars) : '';
}
}
return $output;
}
/**
* When "group_by_bundle" is active, we need to add the bundle name to the
* group, else just return the entity label.
......@@ -284,6 +332,15 @@ class LinkitPluginEntity extends LinkitPlugin {
'#default_value' => isset($this->conf['group_by_bundle']) ? $this->conf['group_by_bundle'] : 0,
);
}
// Reverse menu trail.
$form[$this->plugin['name']]['reverse_menu_trail'] = array(
'#title' => t('Add reverse menu trail to description'),
'#type' => 'checkbox',
'#default_value' => isset($this->conf['reverse_menu_trail']) ? $this->conf['reverse_menu_trail'] : 0,
'#description' => t('If the result has a menu item its menu trail will be added in reverse in the description.'),
);
return $form;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment