From eaf36d7f641e35bb791cc5ced865c6b8b2516b77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20G.=20MARAND?= <fgm@osinet.fr>
Date: Mon, 13 Aug 2012 15:30:14 +0200
Subject: [PATCH] Issue #1553316: home link

---
 breadcrumbs_by_path.module |   94 +++++++++++++++++++++----------------------
 1 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/breadcrumbs_by_path.module b/breadcrumbs_by_path.module
index 99cdfff..3cc82f1 100644
--- a/breadcrumbs_by_path.module
+++ b/breadcrumbs_by_path.module
@@ -1,6 +1,6 @@
 <?php
 /**
- * @file breadcrumbs_by_path.module
+ * @file
  * Creates a breadcrumb trail based on the current aliased path.
  */
 
@@ -20,7 +20,7 @@ function breadcrumbs_by_path_help($path, $arg) {
 function breadcrumbs_by_path_page_alter(&$page) {
   // Start with getting the current URL
   $uri = ltrim(request_uri(), '/');
-  
+
   // build a breadcrumb trail and set the breadcrumb
   $trail = _breadcrumbs_by_path_build_trail($uri);
   drupal_set_breadcrumb($trail);
@@ -31,78 +31,76 @@ function breadcrumbs_by_path_page_alter(&$page) {
  */
 function _breadcrumbs_by_path_build_trail($uri) {
   $trail = array();
-  
-  // if we're on the home page, skip everything and return just the home link
-  if(!drupal_is_front_page()) {
+
+  // If we are on the home page, skip everything and return just the home link.
+  if (!drupal_is_front_page()) {
     $i = 0;
-    
-    // strip the current page from the request
+
+    // Strip the current page from the request.
     $uri = dirname($uri);
-    
-    // recursively trim uri and look for available path
+
+    // Recursively trim uri and look for available path.
     while ($uri && $uri != '.') {
-      
-      // first we see if the uri directs to a valid path
+
+      // First we see if the uri directs to a valid path.
       $path = drupal_lookup_path('source', $uri);
-      
-      // load the menu item for the path
-      if($path) {
+      $trail[$i]['path'] = $uri;
+
+      // Figure out the title of the current item.
+      if ($path) {
         $item = menu_get_item($path);
-      } else {
-        $item = menu_get_item($uri);
-      }
-      
-      // if there is no valid menu item, skip this uri
-      if(!$item) {
-        $uri = dirname($uri);
-        continue;
+        $trail[$i]['title'] = $item['title'];
       }
+      else {
+        // If it is not a valid path, load the menu item for the path.
+        $item = menu_get_item($uri);
 
-      // figure out the title of the current item
-      if($path && isset($item) && !empty($item['title'])) {
-        $trail[$i]['title'] = $item['title'];
-      } else {
-        // original_map holds the full list of args passed in to the menu item
+        // If we still did not get a valid menu item, skip this.
+        if (!$item) {
+          $uri = dirname($uri);
+          continue;
+        }
+
+        // original_map holds the full list of args passed in to the menu item.
         $last_arg = array_pop($item['original_map']);
-        
-        // check to see if the end of the path is the same as the menu path, meaning there are no additional args
-        if($item['path'] == $last_arg) {
+
+        // Check to see if the end of the path is the same as the menu path,
+        // meaning there are no additional args.
+        if ($item['path'] == $last_arg) {
           $trail[$i]['title'] = $item['title'];
-        } else {
+        }
+        else {
           $trail[$i]['title'] = _breadcrumbs_by_path_clean_string($last_arg);
         }
       }
 
-      // set the path for the current crumb
-      $trail[$i]['path'] = $uri;
-      
-      // prepare for the next iteration
+      // Prepare for the next iteration.
       $uri = dirname($uri);
       $i++;
     }
-    
-    // reverse the trail so that it will be in the correct order when returned
+
+    // Reverse the trail so that it will be in the correct order when returned.
     $trail = array_reverse($trail);
   }
-  
-  // now build the actual breadcrumb trail in the right format
-  $bc = array(l('Home', '<front>'));
-  foreach($trail as $c) {
+
+  // Now build the actual breadcrumb trail in the right format.
+  $bc = array(l(t('Home'), '<front>'));
+  foreach ($trail as $c) {
     $bc[] = l($c['title'], $c['path']);
   }
-  
+
   return $bc;
 }
 
 /**
- * Clean a string for display as a breadcrumb title
+ * Clean a string for display as a breadcrumb title.
  */
 function _breadcrumbs_by_path_clean_string($string) {
-  // replace hyphens and underscores with spaces
+  // Replace hyphens and underscores with spaces.
   $string = str_replace(array('-', '_'), ' ', $string);
-  
-  // Make the first character of the title uppercase
-  $string = ucfirst($string);
-  
+
+  // Make the first character of the title uppercase.
+  $string = drupal_ucfirst($string);
+
   return $string;
 }
-- 
1.7.2.5

