Elgg  Version 4.3
breadcrumbs.php
Go to the documentation of this file.
1 <?php
21 function elgg_push_breadcrumb($text, $href = false): void {
22  $breadcrumbs = (array) _elgg_services()->config->breadcrumbs;
23 
24  $breadcrumbs[] = [
25  'text' => $text,
26  'href' => $href,
27  ];
28 
29  elgg_set_config('breadcrumbs', $breadcrumbs);
30 }
31 
38 function elgg_pop_breadcrumb(): array {
39  $breadcrumbs = (array) _elgg_services()->config->breadcrumbs;
40 
41  if (empty($breadcrumbs)) {
42  return [];
43  }
44 
45  $popped = array_pop($breadcrumbs);
46  elgg_set_config('breadcrumbs', $breadcrumbs);
47 
48  return $popped;
49 }
50 
71 function elgg_get_breadcrumbs(array $breadcrumbs = null): array {
72  if (!isset($breadcrumbs)) {
73  // if no crumbs set, still allow hook to populate it
74  $breadcrumbs = (array) _elgg_services()->config->breadcrumbs;
75  }
76 
77  $params = [
78  'breadcrumbs' => $breadcrumbs,
79  ];
80 
81  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
82  $params['segments'] = _elgg_services()->request->getUrlSegments();
83  array_shift($params['segments']);
84 
85  $breadcrumbs = elgg_trigger_plugin_hook('prepare', 'breadcrumbs', $params, $breadcrumbs);
86  if (!is_array($breadcrumbs)) {
87  _elgg_services()->logger->error('"prepare, breadcrumbs" hook must return an array of breadcrumbs');
88  return [];
89  }
90 
91  foreach ($breadcrumbs as $key => $breadcrumb) {
92  // adds name for usage in menu items
93  if (!isset($breadcrumb['name'])) {
94  $breadcrumbs[$key]['name'] = $key;
95  }
96  }
97 
98  return $breadcrumbs;
99 }
100 
109 function elgg_push_entity_breadcrumbs(ElggEntity $entity, $link_self = true): void {
110 
111  $container = $entity->getContainerEntity() ? : null;
112  elgg_push_collection_breadcrumbs($entity->type, $entity->subtype, $container);
113 
114  $entity_url = $link_self ? $entity->getURL() : false;
115  elgg_push_breadcrumb($entity->getDisplayName(), $entity_url);
116 }
117 
128 function elgg_push_collection_breadcrumbs($entity_type, $entity_subtype, ElggEntity $container = null, $friends = false): void {
129 
130  if ($container) {
131  if (!$container instanceof \ElggSite) {
132  elgg_push_breadcrumb($container->getDisplayName(), $container->getURL());
133  }
134 
135  if ($friends) {
136  $collection_route = "collection:$entity_type:$entity_subtype:friends";
137  } else if ($container instanceof ElggUser) {
138  $collection_route = "collection:$entity_type:$entity_subtype:owner";
139  } else if ($container instanceof ElggGroup) {
140  $collection_route = "collection:$entity_type:$entity_subtype:group";
141  } else if ($container instanceof ElggSite) {
142  $collection_route = "collection:$entity_type:$entity_subtype:all";
143  } else {
144  $collection_route = "collection:$entity_type:$entity_subtype:container";
145  }
146 
147  $parameters = _elgg_services()->routes->resolveRouteParameters($collection_route, $container);
148  if ($parameters !== false) {
149  $label = elgg_echo("collection:$entity_type:$entity_subtype");
150  if ($friends) {
151  if (elgg_language_key_exists("collection:$entity_type:$entity_subtype:friends")) {
152  $label = elgg_echo("collection:$entity_type:$entity_subtype:friends");
153  } else {
154  $label = elgg_echo('collection:friends', [$label]);
155  }
156  }
157  $collection_url = elgg_generate_url($collection_route, $parameters);
158  elgg_push_breadcrumb($label, $collection_url);
159  }
160  } else {
161  $label = elgg_echo("collection:$entity_type:$entity_subtype");
162  $collection_url = elgg_generate_url("collection:$entity_type:$entity_subtype:all");
163  elgg_push_breadcrumb($label, $collection_url);
164  }
165 }
elgg_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:46
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
elgg_get_breadcrumbs(array $breadcrumbs=null)
Returns all breadcrumbs as an array [ [ &#39;text&#39; => &#39;Breadcrumb title&#39;, &#39;href&#39; => &#39;/path/to/page&#39;, ] ]
Definition: breadcrumbs.php:71
$params
Saves global plugin settings.
Definition: save.php:13
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($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_pop_breadcrumb()
Removes last breadcrumb entry.
Definition: breadcrumbs.php:38
elgg_push_collection_breadcrumbs($entity_type, $entity_subtype, ElggEntity $container=null, $friends=false)
Resolves and pushes collection breadcrumbs for a container.
$entity
Definition: reset.php:8
elgg_set_config($name, $value)
Set an Elgg configuration value.
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
$container
Definition: delete.php:23
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:380
elgg_push_entity_breadcrumbs(ElggEntity $entity, $link_self=true)
Resolves and pushes entity breadcrumbs based on named routes.
$breadcrumbs
Displays breadcrumbs.
Definition: breadcrumbs.php:22
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
elgg_push_breadcrumb($text, $href=false)
Breadcrumbs Elgg uses a breadcrumb stack.
Definition: breadcrumbs.php:21
getContainerEntity()
Get the container entity for this object.
$text
Definition: button.php:32
getURL()
Gets the URL for this entity.
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318