Elgg  Version 4.3
AdminUsersBulk.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
8 
16 
24  public static function registerActions(\Elgg\Hook $hook) {
25  if (!elgg_is_admin_logged_in()) {
26  return;
27  }
28 
29  /* @var $return MenuItems */
30  $return = $hook->getValue();
31 
32  if ((bool) $hook->getParam('show_ban', true)) {
33  $return[] = \ElggMenuItem::factory([
34  'name' => 'ban',
35  'icon' => 'ban',
36  'text' => elgg_echo('ban'),
37  'href' => elgg_generate_action_url('admin/user/bulk/ban', [], false),
38  'priority' => 100,
39  ]);
40  }
41 
42  if ((bool) $hook->getParam('show_unban', true)) {
43  $return[] = \ElggMenuItem::factory([
44  'name' => 'unban',
45  'icon' => 'ban',
46  'text' => elgg_echo('unban'),
47  'href' => elgg_generate_action_url('admin/user/bulk/unban', [], false),
48  'priority' => 200,
49  ]);
50  }
51 
52  if ((bool) $hook->getParam('show_validate', false)) {
53  $return[] = \ElggMenuItem::factory([
54  'icon' => 'check',
55  'name' => 'validate',
56  'text' => elgg_echo('validate'),
57  'href' => elgg_generate_action_url('admin/user/bulk/validate'),
58  'priority' => 400,
59  ]);
60  }
61 
62  if ((bool) $hook->getParam('show_delete', true)) {
63  $return[] = \ElggMenuItem::factory([
64  'name' => 'delete',
65  'icon' => 'delete',
66  'text' => elgg_echo('delete'),
67  'href' => elgg_generate_action_url('admin/user/bulk/delete', [], false),
68  'confirm' => elgg_echo('deleteconfirm:plural'),
69  'priority' => 900,
70  'link_class' => ['elgg-button-delete'],
71  ]);
72  }
73 
74  return $return;
75  }
76 
84  public static function disableItems(\Elgg\Hook $hook): ?PreparedMenu {
85  $menu = $hook->getValue();
86  if (!$menu instanceof PreparedMenu) {
87  return null;
88  }
89 
90  $disable = function(\ElggMenuItem $menu_item) use (&$disable) {
91  if (!empty($menu_item->getHref())) {
92  $menu_item->disabled = true;
93  }
94 
95  foreach ($menu_item->getChildren() as $child) {
96  $disable($child);
97  }
98  };
99 
100  /* @var $section MenuSection */
101  foreach ($menu as $section) {
102  /* @var $menu_item \ElggMenuItem */
103  foreach ($section as $menu_item) {
104  $disable($menu_item);
105  }
106  }
107 
108  return $menu;
109  }
110 }
static disableItems(\Elgg\Hook $hook)
Disable all items which have a href.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_generate_action_url($action, array $query=[], $add_csrf_tokens=true)
Generate an action URL.
$menu
Admin sidebar – just outputs the page menus.
Definition: sidebar.php:6
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 bulk actions for users.
Elgg Menu Item.
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
static registerActions(\Elgg\Hook $hook)
Add the bulk actions.