From 88e80835b2ad574e0175750eb223f4cabee4e004 Mon Sep 17 00:00:00 2001
From: idebr <idebr@1879760.no-reply.drupal.org>
Date: Mon, 24 Oct 2016 10:19:15 +0200
Subject: [PATCH] Issue #2821613: Configure which menu to use for the
 breadcrumb title

---
 plugins/context_path_breadcrumb_reaction.inc | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/plugins/context_path_breadcrumb_reaction.inc b/plugins/context_path_breadcrumb_reaction.inc
index 38155ac..4e83466 100644
--- a/plugins/context_path_breadcrumb_reaction.inc
+++ b/plugins/context_path_breadcrumb_reaction.inc
@@ -22,6 +22,20 @@ class context_path_breadcrumb_reaction extends context_reaction {
       '#type' => 'checkbox',
       '#default_value' => isset($settings['load_page_titles']) ? $settings['load_page_titles'] : '',
     );
+    $menu_options = menu_get_menus(TRUE);
+    $form['load_page_titles_menu'] = array(
+      '#title' => t('Load the page titles from a specific menu'),
+      '#description' => t("Optionally specify the menu when loading the menu item. This is useful when a path is in multiple menu's."),
+      '#type' => 'select',
+      '#options' => $menu_options,
+      '#default_value' => isset($settings['load_page_titles_menu']) ? $settings['load_page_titles_menu'] : '',
+      '#empty_option' => t('All except management and devel menu'),
+      '#states' => array(
+        'visible' => array(
+          ':input[name="reactions[plugins][path_breadcrumb][load_page_titles]"]' => array('checked' => TRUE),
+        ),
+      ),
+    );
     $form['set_active_trail'] = array(
       '#title' => t('Set the active trail'),
       '#description' => t('Set the active trail for all breadcrumb items found in a menu. This will cost some additional queries so will slow down the page a bit (probably not very much).'),
@@ -57,6 +71,7 @@ class context_path_breadcrumb_reaction extends context_reaction {
       if (isset($v->reactions[$this->plugin])) {
         $current_page_title = isset($v->reactions[$this->plugin]['current_page_title']) && $v->reactions[$this->plugin]['current_page_title'] === 1;
         $load_page_titles = isset($v->reactions[$this->plugin]['load_page_titles']) && $v->reactions[$this->plugin]['load_page_titles'] === 1;
+        $load_page_titles_menu = !empty($v->reactions[$this->plugin]['load_page_titles_menu']) ? $v->reactions[$this->plugin]['load_page_titles_menu'] : FALSE;
         $set_active_trail = isset($v->reactions[$this->plugin]['set_active_trail']) && $v->reactions[$this->plugin]['set_active_trail'] === 1;
         $blacklist = isset($v->reactions[$this->plugin]['blacklist']) ? $v->reactions[$this->plugin]['blacklist'] : '';
 
@@ -103,12 +118,17 @@ class context_path_breadcrumb_reaction extends context_reaction {
 
           // Find link items matching the parent candidates in all menus.
           if (($load_page_titles || $set_active_trail) && $parent_candidates_active) {
-            $results = db_select('menu_links', 'ml')
+            $query = db_select('menu_links', 'ml')
               ->fields('ml',array('menu_name', 'link_path', 'mlid'))
               ->condition('link_path', $parent_candidates_active, 'IN')
               ->condition('menu_name', array('management', 'devel'), 'NOT IN')
-              ->orderBy('depth', 'DESC')
-              ->execute();
+              ->orderBy('depth', 'DESC');
+
+            if ($load_page_titles && $load_page_titles_menu) {
+              $query->condition('menu_name', $load_page_titles_menu);
+            }
+            $results = $query->execute();
+
             $matched_menus = array();
 
             foreach ($results as $record) {
-- 
2.1.0

