Elgg  Version 4.3
Widget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
6 
13 class Widget {
14 
22  public static function registerEdit(\Elgg\Hook $hook) {
23  $widget = $hook->getEntityParam();
24  if (!$widget instanceof \ElggWidget) {
25  return;
26  }
27 
28  if (!(bool) $hook->getParam('show_edit', $widget->canEdit())) {
29  return;
30  }
31 
32  /* @var $return MenuItems */
33  $return = $hook->getValue();
34 
35  $return[] = \ElggMenuItem::factory([
36  'name' => 'settings',
37  'text' => elgg_view_icon('settings-alt'),
38  'title' => elgg_echo('widget:edit'),
39  'href' => "#widget-edit-{$widget->guid}",
40  'link_class' => ['elgg-widget-edit-button', 'elgg-toggle'],
41  'priority' => 800,
42  ]);
43 
44  return $return;
45  }
46 
54  public static function registerDelete(\Elgg\Hook $hook) {
55  $widget = $hook->getEntityParam();
56  if (!$widget instanceof \ElggWidget || !$widget->canDelete()) {
57  return;
58  }
59 
60  /* @var $return MenuItems */
61  $return = $hook->getValue();
62 
63  $return[] = \ElggMenuItem::factory([
64  'name' => 'delete',
65  'text' => elgg_view_icon('delete-alt'),
66  'title' => elgg_echo('widget:delete', [$widget->getDisplayName()]),
67  'href' => elgg_generate_action_url('widgets/delete', [
68  'widget_guid' => $widget->guid,
69  ]),
70  'link_class' => 'elgg-widget-delete-button',
71  'id' => "elgg-widget-delete-button-{$widget->guid}",
72  'data-elgg-widget-type' => $widget->handler,
73  'priority' => 900,
74  ]);
75 
76  return $return;
77  }
78 }
elgg_generate_action_url($action, array $query=[], $add_csrf_tokens=true)
Generate an action URL.
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
Register menu item to the widget menu.
Definition: Widget.php:13
static registerDelete(\Elgg\Hook $hook)
Register the delete menu item for widgets.
Definition: Widget.php:54
if($guid===false) $widget
Definition: add.php:30
static registerEdit(\Elgg\Hook $hook)
Register the edit menu item for widgets.
Definition: Widget.php:22
elgg_view_icon($name, $vars=[])
View an icon glyph.
Definition: views.php:1303