Elgg  Version master
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\Event $event) {
25  if (!elgg_is_admin_logged_in()) {
26  return;
27  }
28 
29  /* @var $return MenuItems */
30  $return = $event->getValue();
31 
32  if ((bool) $event->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) $event->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) $event->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) $event->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\Event $event): ?PreparedMenu {
85  $menu = $event->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 }
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
static disableItems(\Elgg\Event $event)
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
static registerActions(\Elgg\Event $event)
Add the bulk actions.
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 bulk actions for users.
Elgg Menu Item.
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
$menu
Form body for setting up site menu.
Definition: save.php:7
Models an event passed to event handlers.
Definition: Event.php:11