Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
deprecate(breadcrumbs): breadcrumbs now use href instead of link
Fixes #10345
  • Loading branch information
jdalsem committed Dec 4, 2017
1 parent 9dfb83b commit 6e7235a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 21 additions & 5 deletions engine/lib/navigation.php
Expand Up @@ -252,16 +252,20 @@ function elgg_register_title_button($handler = null, $name = 'add', $entity_type
* See elgg_get_breadcrumbs() and the navigation/breadcrumbs view.
*
* @param string $title The title to display. During rendering this is HTML encoded.
* @param string $link Optional. The link for the title. During rendering links are
* @param string $href Optional. The href for the title. During rendering links are
* normalized via elgg_normalize_url().
*
* @return void
* @since 1.8.0
* @see elgg_get_breadcrumbs()
*/
function elgg_push_breadcrumb($title, $link = null) {
function elgg_push_breadcrumb($title, $href = null) {
$breadcrumbs = (array) _elgg_config()->breadcrumbs;
$breadcrumbs[] = ['title' => $title, 'link' => $link];
$breadcrumbs[] = [
'title' => $title,
'href' => $href,
];

elgg_set_config('breadcrumbs', $breadcrumbs);
}

Expand Down Expand Up @@ -290,7 +294,7 @@ function elgg_pop_breadcrumb() {
* [
* [
* 'title' => 'Breadcrumb title',
* 'link' => '/path/to/page',
* 'href' => '/path/to/page',
* ]
* ]
* </code>
Expand Down Expand Up @@ -328,6 +332,18 @@ function elgg_get_breadcrumbs(array $breadcrumbs = null) {
_elgg_services()->logger->error('"prepare, breadcrumbs" hook must return an array of breadcrumbs');
return [];
}

foreach ($breadcrumbs as $key => $breadcrumb) {
if (!isset($breadcrumb['link'])) {
continue;
}

elgg_deprecated_notice("Breadcrumb [{$breadcrumb['title']}] requires 'href' instead of 'link' set in the configuration", '3.0');

$breadcrumb['href'] = $breadcrumb['link'];
unset($breadcrumb['link']);
$breadcrumbs[$key] = $breadcrumb;
}

return $breadcrumbs;
}
Expand All @@ -347,7 +363,7 @@ function elgg_get_breadcrumbs(array $breadcrumbs = null) {
function elgg_prepare_breadcrumbs($hook, $type, $breadcrumbs, $params) {
// remove last crumb if not a link
$last_crumb = end($breadcrumbs);
if (empty($last_crumb['link'])) {
if (empty($last_crumb['href'])) {
array_pop($breadcrumbs);
}

Expand Down
6 changes: 3 additions & 3 deletions views/default/navigation/breadcrumbs.php
Expand Up @@ -12,7 +12,7 @@
* [
* [
* 'title' => 'Breadcrumb title',
* 'link' => '/path/to/page',
* 'href' => '/path/to/page',
* ],
* ]
* </code>
Expand All @@ -36,9 +36,9 @@
// We have to escape text (without double-encoding). Titles in core plugins are HTML escaped
// on input, but we can't guarantee that other users of this view and of elgg_push_breadcrumb()
// will do so.
if (!empty($breadcrumb['link'])) {
if (!empty($breadcrumb['href'])) {
$crumb = elgg_view('output/url', [
'href' => $breadcrumb['link'],
'href' => $breadcrumb['href'],
'text' => $breadcrumb['title'],
'encode_text' => true,
'is_trusted' => true,
Expand Down

0 comments on commit 6e7235a

Please sign in to comment.