Elgg  Version master
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 
35  elgg_push_collection_breadcrumbs($entity->type, $entity->subtype, $entity->getContainerEntity());
36 
37  $link_self = elgg_get_current_route_name() !== "view:{$entity->type}:{$entity->subtype}";
38  if ($link_self) {
39  elgg_register_menu_item('breadcrumbs', [
40  'name' => 'entity',
41  'text' => $entity->getDisplayName(),
42  'href' => $entity->getURL(),
43  ]);
44  }
45 }
46 
57 function elgg_push_collection_breadcrumbs(string $entity_type, string $entity_subtype, \ElggEntity $container = null, bool $friends = false): void {
58 
59  if ($container) {
60  if (!$container instanceof \ElggSite && $entity_type !== 'group') {
61  elgg_register_menu_item('breadcrumbs', [
62  'name' => 'container',
63  'text' => $container->getDisplayName(),
64  'href' => $container->getURL(),
65  ]);
66  }
67 
68  if ($friends) {
69  $collection_route = "collection:{$entity_type}:{$entity_subtype}:friends";
70  } elseif ($entity_type === 'group') {
71  $collection_route = "collection:{$entity_type}:{$entity_subtype}:all";
72  } elseif ($container instanceof \ElggUser) {
73  $collection_route = "collection:{$entity_type}:{$entity_subtype}:owner";
74  } elseif ($container instanceof \ElggGroup) {
75  $collection_route = "collection:{$entity_type}:{$entity_subtype}:group";
76  } elseif ($container instanceof \ElggSite) {
77  $collection_route = "collection:{$entity_type}:{$entity_subtype}:all";
78  } else {
79  $collection_route = "collection:{$entity_type}:{$entity_subtype}:container";
80  }
81 
82  if ($collection_route === elgg_get_current_route_name()) {
83  return;
84  }
85 
86  $parameters = _elgg_services()->routes->resolveRouteParameters($collection_route, $container);
87  if ($parameters !== false) {
88  $label = elgg_echo("collection:{$entity_type}:{$entity_subtype}");
89  if ($friends) {
90  if (elgg_language_key_exists("collection:{$entity_type}:{$entity_subtype}:friends")) {
91  $label = elgg_echo("collection:{$entity_type}:{$entity_subtype}:friends");
92  } else {
93  $label = elgg_echo('collection:friends', [$label]);
94  }
95  }
96 
97  if (elgg_route_exists($collection_route)) {
98  elgg_register_menu_item('breadcrumbs', [
99  'name' => 'collection',
100  'text' => $label,
101  'href' => elgg_generate_url($collection_route, $parameters),
102  ]);
103  }
104  }
105 
106  return;
107  }
108 
109  $all_route_name = "collection:{$entity_type}:{$entity_subtype}:all";
110  if (!elgg_route_exists($all_route_name) || ($all_route_name === elgg_get_current_route_name())) {
111  return;
112  }
113 
114  elgg_register_menu_item('breadcrumbs', [
115  'name' => 'collection',
116  'text' => elgg_echo("collection:{$entity_type}:{$entity_subtype}"),
117  'href' => elgg_generate_url($all_route_name),
118  ]);
119 }
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_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
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_push_entity_breadcrumbs(\ElggEntity $entity)
Resolves and pushes entity breadcrumbs based on named routes.
Definition: breadcrumbs.php:33
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:23
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:57
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
getContainerEntity()
Get the container entity for this object.
Definition: ElggEntity.php:552
$text
Definition: button.php:33
getURL()
Gets the URL for this entity.
Definition: ElggEntity.php:573
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306
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