Elgg  Version 5.1
Go to the documentation of this file.
1 <?php
3 namespace Elgg\Menus;
12 class Breadcrumbs {
22  public static function cleanupBreadcrumbs(\Elgg\Event $event): void {
23  /* @var $breadcrumbs PreparedMenu */
24  $breadcrumbs = $event->getValue();
26  $items = $breadcrumbs->getItems('default');
27  if (empty($items)) {
28  return;
29  }
31  $last = null;
32  foreach ($items as $crumb) {
33  $last = $crumb;
34  $crumb->setText(elgg_get_excerpt((string) $crumb->getText(), 100));
35  }
37  // remove last crumb if it has no link
38  if (empty($last->getHref())) {
39  elgg_log("Having a breadcrumb at the end of the list without a link makes no sense. Please update your code for the '{$last->getText()}[{$last->getID()}]' breadcrumb.", 'NOTICE');
40  $breadcrumbs->getSection('default')->remove($last->getID());
41  } elseif (!$last->getChildren() && elgg_http_url_is_identical(elgg_get_current_url(), $last->getHref())) {
42  elgg_log("Having a breadcrumb at the end of the list which links to the current page makes no sense. Please update your code for the '{$last->getText()}[{$last->getID()}]' breadcrumb.", 'NOTICE');
43  $breadcrumbs->getSection('default')->remove($last->getID());
44  }
45  }
54  public static function addHomeItem(\Elgg\Event $event): ?PreparedMenu {
55  /* @var $return PreparedMenu */
56  $return = $event->getValue();
58  /* @var $items \ElggMenuItem[] */
59  $items = $return->getItems('default');
60  if (empty($items)) {
61  return null;
62  }
65  if (elgg_in_context('admin')) {
66  $href = elgg_generate_url('admin');
67  }
69  array_unshift($items, \ElggMenuItem::factory([
70  'name' => 'home',
71  'icon' => 'home',
72  'text' => false,
73  'title' => elgg_get_site_entity()->getDisplayName(),
74  'href' => $href,
75  ]));
77  $return->getSection('default')->fill($items);
79  return $return;
80  }
81 }
elgg_in_context(string $context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
elgg_get_excerpt(string $text, int $num_chars=250)
Returns an excerpt.
Definition: output.php:83
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
static factory(array $options)
Create an ElggMenuItem from an associative array.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
static cleanupBreadcrumbs(\Elgg\Event $event)
Prepare breadcrumbs before display.
Definition: Breadcrumbs.php:22
Definition: delete.php:8
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
Returns the current page&#39;s complete URL.
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
Get the URL for the current (or specified) site, ending with "/".
Get the current site entity.
Definition: entities.php:98
elgg_http_url_is_identical(string $url1, string $url2, array $ignore_params=['offset', 'limit'])
Test if two URLs are functionally identical.
Definition: elgglib.php:199
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
static addHomeItem(\Elgg\Event $event)
Adds a home item.
Definition: Breadcrumbs.php:54
Layout breadcrumbs.
Definition: breadcrumbs.php:19
Prepares breadcrumbs.
Definition: Breadcrumbs.php:12
Models an event passed to event handlers.
Definition: Event.php:11