summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Stjerneman2013-03-08 14:16:39 (GMT)
committerEmil Stjerneman2013-03-08 14:16:39 (GMT)
commit48c3ac1c9fab1e754431d6d7bb08839c8a488758 (patch)
tree1a9270f2bd8584a208f5335cd4a93eb54ce54b43
parent45ecd8d657b952bd1e15e656d02994b7f180c7de (diff)
Added #1914236 by emattias, anon: Show reverse menu trail if result has menu item(s).
-rw-r--r--linkit.module4
-rw-r--r--linkit.theme.inc16
-rw-r--r--plugins/linkit_plugins/linkit-plugin-entity.class.php57
3 files changed, 77 insertions, 0 deletions
diff --git a/linkit.module b/linkit.module
index 6b17c7e..2679a3e 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 7ad87dd..dd56e9b 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 = '<p>' . implode($variables['separator'], $menu_trail) . '</p>';
+ 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 bbe081f..3e80b0e 100644
--- a/plugins/linkit_plugins/linkit-plugin-entity.class.php
+++ b/plugins/linkit_plugins/linkit-plugin-entity.class.php
@@ -105,10 +105,58 @@ 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