Elgg  Version 5.1
breadcrumbs.php
Go to the documentation of this file.
1 <?php
16 function elgg_push_breadcrumb(string $text, string|false $href = false): void {
17  static $i = 0;
18  $i++;
19  elgg_register_menu_item('breadcrumbs', [
20  'name' => "breadcrumb-{$i}",
21  'text' => $text,
22  'href' => $href,
23  ]);
24 }
25 
34 function elgg_push_entity_breadcrumbs(\ElggEntity $entity, bool $link_self = null): void {
35 
36  elgg_push_collection_breadcrumbs($entity->type, $entity->subtype, $entity->getContainerEntity());
37 
38  if (isset($link_self)) {
39  elgg_deprecated_notice('Using link_self argument is deprecated. A link to self will always be added if not on the "view" route of the entity.', '5.1');
40  } else {
41  $link_self = elgg_get_current_route_name() !== "view:{$entity->type}:{$entity->subtype}";
42  }
43 
44  if ($link_self) {
45  elgg_register_menu_item('breadcrumbs', [
46  'name' => 'entity',
47  'text' => $entity->getDisplayName(),
48  'href' => $entity->getURL(),
49  ]);
50  }
51 }
52 
63 function elgg_push_collection_breadcrumbs(string $entity_type, string $entity_subtype, \ElggEntity $container = null, bool $friends = false): void {
64 
65  if ($container) {
66  if (!$container instanceof \ElggSite && $entity_type !== 'group') {
67  elgg_register_menu_item('breadcrumbs', [
68  'name' => 'container',
69  'text' => $container->getDisplayName(),
70  'href' => $container->getURL(),
71  ]);
72  }
73 
74  if ($friends) {
75  $collection_route = "collection:{$entity_type}:{$entity_subtype}:friends";
76  } elseif ($entity_type === 'group') {
77  $collection_route = "collection:{$entity_type}:{$entity_subtype}:all";
78  } elseif ($container instanceof \ElggUser) {
79  $collection_route = "collection:{$entity_type}:{$entity_subtype}:owner";
80  } elseif ($container instanceof \ElggGroup) {
81  $collection_route = "collection:{$entity_type}:{$entity_subtype}:group";
82  } elseif ($container instanceof \ElggSite) {
83  $collection_route = "collection:{$entity_type}:{$entity_subtype}:all";
84  } else {
85  $collection_route = "collection:{$entity_type}:{$entity_subtype}:container";
86  }
87 
88  if ($collection_route === elgg_get_current_route_name()) {
89  return;
90  }
91 
92  $parameters = _elgg_services()->routes->resolveRouteParameters($collection_route, $container);
93  if ($parameters !== false) {
94  $label = elgg_echo("collection:{$entity_type}:{$entity_subtype}");
95  if ($friends) {
96  if (elgg_language_key_exists("collection:{$entity_type}:{$entity_subtype}:friends")) {
97  $label = elgg_echo("collection:{$entity_type}:{$entity_subtype}:friends");
98  } else {
99  $label = elgg_echo('collection:friends', [$label]);
100  }
101  }
102 
103  if (elgg_route_exists($collection_route)) {
104  elgg_register_menu_item('breadcrumbs', [
105  'name' => 'collection',
106  'text' => $label,
107  'href' => elgg_generate_url($collection_route, $parameters),
108  ]);
109  }
110  }
111 
112  return;
113  }
114 
115  $all_route_name = "collection:{$entity_type}:{$entity_subtype}:all";
116  if (!elgg_route_exists($all_route_name) || ($all_route_name === elgg_get_current_route_name())) {
117  return;
118  }
119 
120  elgg_register_menu_item('breadcrumbs', [
121  'name' => 'collection',
122  'text' => elgg_echo("collection:{$entity_type}:{$entity_subtype}"),
123  'href' => elgg_generate_url($all_route_name),
124  ]);
125 }
elgg_push_breadcrumb(string $text, string|false $href=false)
Breadcrumbs.
Definition: breadcrumbs.php:16
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:115
elgg_route_exists(string $name)
Check if a route is registered.
elgg_get_current_route_name()
Get the route name for the current request.
Definition: pagehandler.php:98
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
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_push_entity_breadcrumbs(\ElggEntity $entity, bool $link_self=null)
Resolves and pushes entity breadcrumbs based on named routes.
Definition: breadcrumbs.php:34
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
$entity
Definition: reset.php:8
$container
Definition: delete.php:24
elgg_push_collection_breadcrumbs(string $entity_type, string $entity_subtype,\ElggEntity $container=null, bool $friends=false)
Resolves and pushes collection breadcrumbs for a container.
Definition: breadcrumbs.php:63
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
getContainerEntity()
Get the container entity for this object.
$text
Definition: button.php:33
getURL()
Gets the URL for this entity.
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:312
elgg_register_menu_item(string $menu_name, array|\ElggMenuItem $menu_item)
Elgg navigation library Functions for managing menus and other navigational elements.
Definition: navigation.php:83