Elgg  Version 4.3
CreateAdminWidgetsHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Widgets;
4 
11 
19  public function __invoke(\Elgg\Event $event) {
20  $user = $event->getObject();
21 
22  elgg_call(ELGG_IGNORE_ACCESS, function() use ($user) {
23  // check if the user already has widgets
24  if (elgg_get_widgets($user->guid, 'admin')) {
25  return;
26  }
27 
28  // In the form column => array of handlers in order, top to bottom
29  $adminWidgets = [
30  1 => ['admin_welcome', 'content_stats'],
31  2 => ['online_users', 'new_users'],
32  ];
33 
34  foreach ($adminWidgets as $column => $handlers) {
35  foreach ($handlers as $position => $handler) {
36  $guid = elgg_create_widget($user->guid, $handler, 'admin');
37  if ($guid === false) {
38  continue;
39  }
40 
41  /* @var \ElggWidget $widget */
43  $widget->move($column, $position);
44  }
45  }
46  });
47  }
48 }
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:592
$column
Definition: add.php:10
$position
Definition: move.php:7
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:146
elgg_get_widgets($owner_guid, $context)
Elgg widgets library.
Definition: widgets.php:20
$user
Definition: ban.php:7
foreach($paths as $path)
Definition: autoloader.php:12
Models an event passed to event handlers.
Definition: Event.php:11
if($guid===false) $widget
Definition: add.php:30
$handler
Definition: add.php:7
elgg_create_widget($owner_guid, $handler, $context, $access_id=null)
Create a new widget instance.
Definition: widgets.php:35
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69
__invoke(\Elgg\Event $event)
Adds default admin widgets to the admin dashboard.