Elgg  Version 6.1
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  if (empty($user->guid)) {
24  // do not create widgets for unsaved entities... probably during unit testing
25  return;
26  }
27 
28  // check if the user already has widgets
29  if (elgg_get_widgets($user->guid, 'admin')) {
30  return;
31  }
32 
33  // In the form column => array of handlers in order, top to bottom
34  $adminWidgets = [
35  1 => ['admin_welcome', 'elgg_blog', 'content_stats'],
36  2 => ['online_users', 'new_users'],
37  ];
38 
39  foreach ($adminWidgets as $column => $handlers) {
40  foreach ($handlers as $position => $handler) {
41  $guid = elgg_create_widget($user->guid, $handler, 'admin');
42  if ($guid === false) {
43  continue;
44  }
45 
46  /* @var \ElggWidget $widget */
48  $widget->move($column, $position);
49  }
50  }
51  });
52  }
53 }
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:306
if(parse_url(elgg_get_site_url(), PHP_URL_PATH)!== '/') if(file_exists(elgg_get_root_path(). 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$position
Definition: add.php:11
$column
Definition: add.php:10
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
elgg_create_widget(int $owner_guid, string $handler, string $context, int $access_id=null)
Create a new widget instance.
Definition: widgets.php:35
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
$user
Definition: ban.php:7
foreach($paths as $path)
Definition: autoloader.php:12
if($guid===false) $widget
Definition: add.php:31
elgg_get_widgets(int $owner_guid, string $context)
Elgg widgets library.
Definition: widgets.php:20
$handler
Definition: add.php:7
Models an event passed to event handlers.
Definition: Event.php:11
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
__invoke(\Elgg\Event $event)
Adds default admin widgets to the admin dashboard.