diff --git a/linkit.module b/linkit.module index 6b17c7e165230590684e4ba8bdf356330b1dcd9d..2679a3e473cad33ddf1d96ff6f64a424fcf0456a 100644 --- a/linkit.module +++ b/linkit.module @@ -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' + ) ); } diff --git a/linkit.theme.inc b/linkit.theme.inc index 7ad87dd6b3ffd5a01349e1e4f82764741f4932f3..dd56e9b2231445998a55fda72de2e9b47ae0850b 100644 --- a/linkit.theme.inc +++ b/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 = '

' . implode($variables['separator'], $menu_trail) . '

'; + return $output; + } } \ No newline at end of file diff --git a/plugins/linkit_plugins/linkit-plugin-entity.class.php b/plugins/linkit_plugins/linkit-plugin-entity.class.php index bbe081f40305267b72ec65165e8db0cd4ae737fe..3e80b0e29b7bf26a11fd319cc96122e9a495d34b 100644 --- a/plugins/linkit_plugins/linkit-plugin-entity.class.php +++ b/plugins/linkit_plugins/linkit-plugin-entity.class.php @@ -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