Elgg  Version master
navigation.php
Go to the documentation of this file.
1 <?php
83 function elgg_register_menu_item(string $menu_name, array|\ElggMenuItem $menu_item): void {
84  if (is_array($menu_item)) {
85  $menu_item = \ElggMenuItem::factory($menu_item);
86  }
87 
88  _elgg_services()->menus->registerMenuItem($menu_name, $menu_item);
89 }
90 
100 function elgg_unregister_menu_item(string $menu_name, string $item_name): ?\ElggMenuItem {
101  return _elgg_services()->menus->unregisterMenuItem($menu_name, $item_name);
102 }
103 
120 function elgg_register_title_button(string $name = 'add', string $entity_type = '', string $entity_subtype = ''): void {
121 
123  if (!$owner) {
124  // noone owns the page so this is probably an all site list page
126  }
127 
128  if ($name === 'add' && $owner instanceof \ElggUser) {
129  // make sure the add link goes to the current logged in user, not the page owner
130  $logged_in_user = elgg_get_logged_in_user_entity();
131  if (!empty($logged_in_user) && ($logged_in_user->guid !== $owner->guid)) {
132  // change the 'owner' for the link to the current logged in user
133  $owner = $logged_in_user;
134  }
135  }
136 
137  // do we have an owner and is the current user allowed to create content here
138  if (!$owner instanceof \ElggEntity || empty($entity_type) || empty($entity_subtype) || !$owner->canWriteToContainer(0, $entity_type, $entity_subtype)) {
139  return;
140  }
141 
142  $href = elgg_generate_url("{$name}:{$entity_type}:{$entity_subtype}", [
143  'guid' => $owner->guid,
144  ]);
145 
146  if (elgg_language_key_exists("{$name}:{$entity_type}:{$entity_subtype}")) {
147  $text = elgg_echo("{$name}:{$entity_type}:{$entity_subtype}");
148  } else {
149  $text = elgg_echo($name);
150  }
151 
152  // register the title menu item
153  elgg_register_menu_item('title', [
154  'name' => $name,
155  'icon' => $name === 'add' ? 'plus' : '',
156  'href' => $href,
157  'text' => $text,
158  'link_class' => 'elgg-button elgg-button-action',
159  ]);
160 }
elgg_unregister_menu_item(string $menu_name, string $item_name)
Remove an item from a menu.
Definition: navigation.php:100
$owner
Definition: upload.php:7
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
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
static factory(array $options)
Create an ElggMenuItem from an associative array.
elgg_register_title_button(string $name= 'add', string $entity_type= '', string $entity_subtype= '')
Convenience function for registering a button to the title menu.
Definition: navigation.php:120
Elgg Menu Item.
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
$text
Definition: button.php:33
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