Elgg  Version 4.3
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\Hook $hook) {
24  $user = $hook->getEntityParam();
25  if (!$user instanceof \ElggUser || !$user->canEdit()) {
26  return;
27  }
28 
29  /* @var $return MenuItems */
30  $return = $hook->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\Hook $hook) {
51  $entity = $hook->getEntityParam();
52  if (!$entity instanceof \ElggEntity) {
53  return;
54  }
55 
56  $return = $hook->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  continue;
73  }
74 
75  switch ($menu_item->getName()) {
76  case 'edit':
77  $menu_item->addLinkClass('elgg-button');
78  $menu_item->addLinkClass('elgg-button-action');
79 
80  $menu_item->setSection('z-last');
81  break;
82  default:
83  if ($menu_item->getSection() === 'default') {
84  $menu_item->setParentName('title-menu-toggle');
85  $menu_item->setSection('z-last');
86  } else {
87  $menu_item->addLinkClass('elgg-button');
88  $menu_item->addLinkClass('elgg-button-action');
89  }
90  break;
91  }
92 
93  $return->add($menu_item);
94  }
95 
96  $return->add(\ElggMenuItem::factory([
97  'name' => 'title-menu-toggle',
98  'icon' => 'ellipsis-v',
99  'href' => false,
100  'text' => '',
101  'child_menu' => [
102  'display' => 'dropdown',
103  'data-position' => json_encode([
104  'at' => 'right bottom',
105  'my' => 'right top',
106  'collision' => 'fit fit',
107  ]),
108  'class' => "elgg-{$hook->getParam('name')}-dropdown-menu",
109  ],
110  'show_with_empty_children' => false,
111  'link_class' => [
112  'elgg-button',
113  'elgg-button-action',
114  ],
115  'priority' => 999,
116  'section' => 'z-last',
117  ]));
118 
119  return $return;
120  }
121 }
static registerEntityToTitle(\Elgg\Hook $hook)
Move entity menu items to the title menu.
Definition: Title.php:50
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
Register menu items to the title menu.
Definition: Title.php:14
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
$entity
Definition: reset.php:8
static registerAvatarEdit(\Elgg\Hook $hook)
Add a link to the avatar edit page.
Definition: Title.php:23
$user
Definition: ban.php:7
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
A collection of menu items.
Definition: MenuItems.php:10
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.