From 34afaf8f2892d5188a72e200b198fa8b9a2ef247 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= <gabor@hojtsy.hu>
Date: Thu, 27 Dec 2007 14:03:37 +0000
Subject: [PATCH] #176748 follow up by pwolanin: fix bad breadcrumbs and
 missing/wrong titles

---
 includes/menu.inc               | 40 ++++++++++++++++++++++++++-------
 modules/filter/filter.admin.inc |  5 +----
 modules/filter/filter.module    |  9 ++++++++
 modules/node/node.pages.inc     |  1 +
 modules/user/user.module        | 12 ++++++++++
 5 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/includes/menu.inc b/includes/menu.inc
index d302ae5f34e6..745323a2b8ae 100644
--- a/includes/menu.inc
+++ b/includes/menu.inc
@@ -464,7 +464,7 @@ function _menu_item_localize(&$item, $map) {
       $item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));
     }
   }
-  else {
+  elseif ($callback) {
     if (empty($item['title_arguments'])) {
       $item['title'] = $callback($item['title']);
     }
@@ -579,6 +579,7 @@ function menu_tail_to_arg($arg, $map, $index) {
  *   $item['title'] is generated from link_title, and may be localized.
  */
 function _menu_link_translate(&$item) {
+  $item['options'] = unserialize($item['options']);
   if ($item['external']) {
     $item['access'] = 1;
     $map = array();
@@ -604,16 +605,33 @@ function _menu_link_translate(&$item) {
       }
       _menu_check_access($item, $map);
     }
-    // If the link title matches that of a router item, localize it.
-    if (!empty($item['title']) && (($item['title'] == $item['link_title']) || ($item['title_callback'] != 't'))) {
-      _menu_item_localize($item, $map);
+    
+    // If the link title matches that of its router item, localize it.
+    if (!empty($item['title']) && ($item['title'] == $item['link_title'])){
+      if (!empty($item['title_arguments']) && $item['title_callback'] == 't') {
+        $item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));
+      }
+      else {
+        $item['title'] = t($item['title']);
+      }
     }
     else {
       $item['title'] = $item['link_title'];
     }
+    // Localize the description and title attribute.
+    if (!empty($item['description'])) {
+      $original_description = $item['description'];
+      $item['description'] = t($item['description']);
+      // Localize the title attribute only if it matches the description.
+      if ($item['options']['attributes']['title'] == $original_description) {
+        $item['options']['attributes']['title'] = $item['description'];
+      }
+    }
+    // Store the map if it may be needed for use later by a title callback.
+    if (!empty($item['title_callback']) && ($item['title_callback'] != 't')) {
+      $item['map'] = $map;
+    }
   }
-  $item['options'] = unserialize($item['options']);
-
   return $map;
 }
 
@@ -759,7 +777,7 @@ function menu_tree_all_data($menu_name = 'navigation', $item = NULL) {
       // LEFT JOIN since there is no match in {menu_router} for an external
       // link.
       $data['tree'] = menu_tree_data(db_query("
-        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
+        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
         FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
         WHERE ml.menu_name = '%s'". $where ."
         ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
@@ -849,7 +867,7 @@ function menu_tree_page_data($menu_name = 'navigation') {
         // LEFT JOIN since there is no match in {menu_router} for an external
         // link.
         $data['tree'] = menu_tree_data(db_query("
-          SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, ml.*
+          SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
           FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
           WHERE ml.menu_name = '%s' AND ml.plid IN (". $placeholders .")
           ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args), $parents);
@@ -1445,6 +1463,12 @@ function menu_set_active_trail($new_trail = NULL) {
     if ($trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
       $trail[] = $item;
     }
+    // Apply title callbacks for items in the active trail (breadcrumb).
+    foreach ($trail as $key => $item) {
+      if (!empty($item['title_callback']) && $item['title_callback'] != 't') {
+        _menu_item_localize($trail[$key], $item['map']);
+      }
+    }
   }
   return $trail;
 }
diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc
index 96e010d44078..03b98be7bdcc 100644
--- a/modules/filter/filter.admin.inc
+++ b/modules/filter/filter.admin.inc
@@ -74,16 +74,13 @@ function theme_filter_admin_overview($form) {
 }
 
 /**
- * Display a filter format form.
+ * Menu callback; Display a filter format form.
  */
 function filter_admin_format_page($format = NULL) {
   if (!isset($format->name)) {
     drupal_set_title(t("Add input format"));
     $format = (object)array('name' => '', 'roles' => '', 'format' => '');
   }
-  else {
-    drupal_set_title(t("%format input format", array('%format' => $format->name)));
-  }
   return drupal_get_form('filter_admin_format_form', $format);
 }
 
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index a8106a709b3a..ed3eddcb2fdb 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -102,6 +102,8 @@ function filter_menu() {
   );
   $items['admin/settings/filters/%filter_format'] = array(
     'type' => MENU_CALLBACK,
+    'title callback' => 'filter_admin_format_title',
+    'title arguments' => array(3),
     'page callback' => 'filter_admin_format_page',
     'page arguments' => array(3),
     'access arguments' => array('administer filters'),
@@ -137,6 +139,13 @@ function filter_format_load($arg) {
   return filter_formats($arg);
 }
 
+/**
+ * Display a filter format form title.
+ */
+function filter_admin_format_title($format) {
+  return $format->name;
+}
+
 /**
  * Implementation of hook_perm().
  */
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index e608dc922605..66f781aee942 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -11,6 +11,7 @@
  * Menu callback; presents the node editing form, or redirects to delete confirmation.
  */
 function node_page_edit($node) {
+  drupal_set_title($node->title);
   return drupal_get_form($node->type .'_node_form', $node);
 }
 
diff --git a/modules/user/user.module b/modules/user/user.module
index 786443e12ae8..fcc8af2f3ce2 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -1029,6 +1029,8 @@ function user_menu() {
 
   $items['user/%user_current'] = array(
     'title' => 'My account',
+    'title callback' => 'user_page_title',
+    'title arguments' => array(1),
     'page callback' => 'user_view',
     'page arguments' => array(1),
     'access callback' => 'user_view_access',
@@ -1151,6 +1153,16 @@ function user_current_to_arg($arg) {
   return empty($arg) || $arg == '%' ? $GLOBALS['user']->uid : $arg;
 }
 
+/**
+ * Menu item title callback - use the user name if it's not the current user.
+ */
+function user_page_title($account) {
+  if ($account->uid == $GLOBALS['user']->uid) {
+    return t('My account');
+  }
+  return $account->name;
+}
+
 /**
  * Accepts an user object, $account, or a DA name and returns an associative
  * array of modules and DA names. Called at external login.
-- 
GitLab