Elgg  Version 6.1
Title.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
7 
14 class Title {
15 
23  public static function registerAvatarEdit(\Elgg\Event $event) {
24  $user = $event->getEntityParam();
25  if (!$user instanceof \ElggUser || !$user->canEdit()) {
26  return;
27  }
28 
29  /* @var $return MenuItems */
30  $return = $event->getValue();
31 
32  $return[] = \ElggMenuItem::factory([
33  'name' => 'avatar:edit',
34  'icon' => 'image',
35  'text' => elgg_echo('avatar:edit'),
36  'href' => elgg_generate_entity_url($user, 'edit', 'avatar'),
37  'link_class' => ['elgg-button', 'elgg-button-action'],
38  ]);
39 
40  return $return;
41  }
42 
50  public static function registerEntityToTitle(\Elgg\Event $event) {
51  $entity = $event->getEntityParam();
52  if (!$entity instanceof \ElggEntity) {
53  return;
54  }
55 
56  $return = $event->getValue();
57  if (!$return instanceof MenuItems) {
58  return;
59  }
60 
61  $entity_menu = _elgg_services()->menus->getUnpreparedMenu('entity', [
62  'entity' => $entity,
63  ]);
64 
65  /* @var $menu_item \ElggmenuItem */
66  foreach ($entity_menu->getItems() as $menu_item) {
67  if ($return->has($menu_item->getName())) {
68  if ($menu_item->getName() === 'edit') {
69  // move edit always to z-last location
70  $return->get('edit')->setSection('z-last');
71  }
72 
73  continue;
74  }
75 
76  switch ($menu_item->getName()) {
77  case 'edit':
78  $menu_item->addLinkClass('elgg-button');
79  $menu_item->addLinkClass('elgg-button-action');
80 
81  $menu_item->setSection('z-last');
82  break;
83  default:
84  if ($menu_item->getSection() === 'default') {
85  $menu_item->setParentName('title-menu-toggle');
86  $menu_item->setSection('z-last');
87  } else {
88  $menu_item->addLinkClass('elgg-button');
89  $menu_item->addLinkClass('elgg-button-action');
90  }
91  break;
92  }
93 
94  $return->add($menu_item);
95  }
96 
97  $return->add(\ElggMenuItem::factory([
98  'name' => 'title-menu-toggle',
99  'icon' => 'ellipsis-v',
100  'href' => false,
101  'text' => '',
102  'title' => elgg_echo('more'),
103  'child_menu' => [
104  'display' => 'dropdown',
105  'data-position' => json_encode([
106  'at' => 'right bottom',
107  'my' => 'right top',
108  'collision' => 'fit fit',
109  ]),
110  'class' => "elgg-{$event->getParam('name')}-dropdown-menu",
111  ],
112  'show_with_empty_children' => false,
113  'link_class' => [
114  'elgg-button',
115  'elgg-button-action',
116  ],
117  'priority' => 999,
118  'section' => 'z-last',
119  ]));
120 
121  return $return;
122  }
123 }
static registerAvatarEdit(\Elgg\Event $event)
Add a link to the avatar edit page.
Definition: Title.php:23
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.
Register menu items to the title menu.
Definition: Title.php:14
$entity
Definition: reset.php:8
elgg_generate_entity_url(ElggEntity $entity, string $resource= 'view', string $subresource=null, array $parameters=[])
Generate entity URL from a named route.
$user
Definition: ban.php:7
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
static registerEntityToTitle(\Elgg\Event $event)
Move entity menu items to the title menu.
Definition: Title.php:50
A collection of menu items.
Definition: MenuItems.php:10
Models an event passed to event handlers.
Definition: Event.php:11