Elgg  Version 6.1
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\Event $event) {
23  $widget = $event->getEntityParam();
24  if (!$widget instanceof \ElggWidget) {
25  return;
26  }
27 
28  if (!(bool) $event->getParam('show_edit', $widget->canEdit())) {
29  return;
30  }
31 
32  /* @var $return MenuItems */
33  $return = $event->getValue();
34 
35  $return[] = \ElggMenuItem::factory([
36  'name' => 'settings',
37  'text' => elgg_view_icon('settings-alt'),
38  'title' => elgg_echo('widget:edit'),
39  'href' => elgg_http_add_url_query_elements('ajax/view/object/widget/edit', [
40  'guid' => $widget->guid,
41  'show_access' => $event->getParam('show_access', true),
42  ]),
43  'data-colorbox-opts' => json_encode([
44  'width' => 750,
45  'max-height' => '80%',
46  'trapFocus' => false,
47  'fixed' => true,
48  ]),
49  'link_class' => ['elgg-widget-edit-button', 'elgg-lightbox'],
50  'priority' => 800,
51  ]);
52 
53  return $return;
54  }
55 
63  public static function registerDelete(\Elgg\Event $event) {
64  $widget = $event->getEntityParam();
65  if (!$widget instanceof \ElggWidget || !$widget->canDelete()) {
66  return;
67  }
68 
69  /* @var $return MenuItems */
70  $return = $event->getValue();
71 
72  $return[] = \ElggMenuItem::factory([
73  'name' => 'delete',
74  'text' => elgg_view_icon('delete-alt'),
75  'title' => elgg_echo('widget:delete', [$widget->getDisplayName()]),
76  'href' => elgg_generate_action_url('widgets/delete', [
77  'widget_guid' => $widget->guid,
78  ]),
79  'confirm' => elgg_echo('deleteconfirm'),
80  'link_class' => 'elgg-widget-delete-button',
81  'id' => "elgg-widget-delete-button-{$widget->guid}",
82  'data-elgg-widget-type' => $widget->handler,
83  'priority' => 900,
84  ]);
85 
86  return $return;
87  }
88 }
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
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 item to the widget menu.
Definition: Widget.php:13
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:183
if($guid===false) $widget
Definition: add.php:31
elgg_view_icon(string $name, array $vars=[])
View an icon glyph.
Definition: views.php:1261
static registerEdit(\Elgg\Event $event)
Register the edit menu item for widgets.
Definition: Widget.php:22
static registerDelete(\Elgg\Event $event)
Register the delete menu item for widgets.
Definition: Widget.php:63
Models an event passed to event handlers.
Definition: Event.php:11