Permalink
Browse files

fix(breadcrumbs): hide the last breadcrumb if it’s not a link

Fixes #6419
  • Loading branch information...
mrclay committed Jan 27, 2015
1 parent a6cca47 commit a1bec58f57fd15e44b1c8990c8928a2ff742347c
Showing with 46 additions and 3 deletions.
  1. +24 −1 docs/guides/upgrading.rst
  2. +9 −2 engine/lib/navigation.php
  3. +13 −0 engine/tests/phpunit/ElggBreadcrumbsTest.php
View
@@ -3,12 +3,35 @@ Upgrading Plugins
Prepare your plugin for the next version of Elgg.
-See the administator guides for :doc:`how to upgrade a live site </admin/upgrading>`.
+See the administrator guides for :doc:`how to upgrade a live site </admin/upgrading>`.
.. contents:: Contents
:local:
:depth: 2
+From 1.11 to 2.0
+================
+
+Breadcrumb display now removes the last item if it does not contain a link. To restore the previous behavior,
+replace the plugin hook handler ``elgg_prepare_breadcrumbs`` with your own:
+
+.. code:: php
+
+ elgg_unregister_plugin_hook_handler('prepare', 'breadcrumbs', 'elgg_prepare_breadcrumbs');
+ elgg_register_plugin_hook_handler('prepare', 'breadcrumbs', 'myplugin_prepare_breadcrumbs');
+
+ function myplugin_prepare_breadcrumbs($hook, $type, $breadcrumbs, $params) {
+ // just apply excerpt to titles
+ foreach (array_keys($breadcrumbs) as $i) {
+ $breadcrumbs[$i]['title'] = elgg_get_excerpt($breadcrumbs[$i]['title'], 100);
+ }
+ return $breadcrumbs;
+ }
+
+
+From 1.10 to 1.11
+=================
+
From 1.9 to 1.10
================
View
@@ -297,8 +297,8 @@ function elgg_get_breadcrumbs() {
}
/**
- * Hook handler to turn titles into 100-character excerpts. To remove this behavior, unregister this
- * function from the [prepare, breadcrumbs] hook.
+ * Prepare breadcrumbs before display. This turns titles into 100-character excerpts, and also
+ * removes the last crumb if it's not a link.
*
* @param string $hook "prepare"
* @param string $type "breadcrumbs"
@@ -309,6 +309,13 @@ function elgg_get_breadcrumbs() {
* @since 1.11
*/
function elgg_prepare_breadcrumbs($hook, $type, $breadcrumbs, $params) {
+ // remove last crumb if not a link
+ $last_crumb = end($breadcrumbs);
+ if (empty($last_crumb['link'])) {
+ array_pop($breadcrumbs);
+ }
+
+ // apply excerpt to titles
foreach (array_keys($breadcrumbs) as $i) {
$breadcrumbs[$i]['title'] = elgg_get_excerpt($breadcrumbs[$i]['title'], 100);
}
@@ -95,4 +95,17 @@ public function testCrumbLinksAreNormalized() {
$html = elgg_view('navigation/breadcrumbs');
$this->assertNotFalse(strpos($html, '"http://localhost/link"'));
}
+
+ public function testTrailingNonLinkIsRemoved() {
+ $this->markTestIncomplete('Needs DB');
+
+ // TODO make this unnecessary
+ elgg_set_view_location('output/url', __DIR__ . '/../../../views/');
+ elgg_set_view_location('navigation/breadcrumbs', __DIR__ . '/../../../views/');
+
+ elgg_push_breadcrumb('Foo', 'foo');
+ elgg_push_breadcrumb('Bar');
+ $html = elgg_view('navigation/breadcrumbs');
+ $this->assertFalse(strpos($html, 'Bar'));
+ }
}

0 comments on commit a1bec58

Please sign in to comment.