Elgg  Version 3.0
add_panel.php
Go to the documentation of this file.
1 <?php
10 
11 // restoring context stack
12 $context_stack = get_input('context_stack');
13 if (!empty($context_stack) && is_array($context_stack)) {
15 }
16 
17 elgg_require_js('resources/widgets/add_panel');
18 
19 $context = elgg_extract('context', $vars, get_input('context'));
20 $owner_guid = (int) elgg_extract('owner_guid', $vars, (int) get_input('owner_guid'));
22 
24 
26 
29  'context' => $context,
30  'container' => $owner,
31 ]);
32 uasort($widget_types, function ($a, $b) {
33  return strcmp($a->name, $b->name);
34 });
35 
37 foreach ($widgets as $column_widgets) {
38  foreach ($column_widgets as $widget) {
39  $current_handlers[] = $widget->handler;
40  }
41 }
42 
44  'class' => 'elgg-text-help',
45 ], elgg_echo('widgets:add:description'));
46 
48 foreach ($widget_types as $handler => $widget_type) {
49  $class = [];
50  // check if widget added and only one instance allowed
51  if (!$widget_type->multiple && in_array($handler, $current_handlers)) {
52  $class[] = 'elgg-state-unavailable';
53  } else {
54  $class[] = 'elgg-state-available';
55  }
56 
57  $class[] = $widget_type->multiple ? 'elgg-widget-multiple' : 'elgg-widget-single';
58 
59  $action = '<div class="elgg-widgets-add-actions elgg-level">';
60  if (!$widget_type->multiple) {
61  $action .= elgg_format_element('span', ['class' => 'elgg-quiet'], elgg_echo('widget:unavailable'));
62  }
63  $add_link = elgg_http_add_url_query_elements('action/widgets/add', [
64  'handler' => $handler,
65  'page_owner_guid' => $owner_guid,
66  'context' => $context,
67  'show_access' => elgg_extract('show_access', $vars),
68  'default_widgets' => elgg_in_context('default_widgets'),
69  ]);
70 
71  $action .= elgg_view('output/url', [
72  'class' => 'elgg-button elgg-button-submit elgg-size-small',
73  'text' => elgg_echo('add'),
74  'href' => $add_link,
75  'is_action' => true,
76  ]);
77  $action .= '</div>';
78 
79  $description = "<h4>{$widget_type->name}</h4>";
80 
81  if ($widget_type->description) {
82  $description .= elgg_format_element('div', ['class' => 'elgg-quiet'], $widget_type->description);
83  }
84 
86  'class' => 'elgg-widgets-add-description',
87  ], $description);
88 
89  $item_content = elgg_format_element('div', [
90  'class' => 'elgg-level',
91  ], $description . $action);
92 
94  'class' => $class,
95  'data-elgg-widget-type' => $handler,
96  ], $item_content);
97 }
98 
99 $result .= "<ul>$list_items</ul>";
100 
101 echo elgg_view_module('aside', elgg_echo('widgets:add'), $result, ['class' => 'elgg-widgets-add-panel']);
$context_stack
Definition: add_panel.php:12
$context
Definition: add_panel.php:19
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:942
$action
Definition: full.php:111
$widget_types
Definition: add_panel.php:28
$list_items
Definition: add_panel.php:47
elgg_get_widget_types($context="")
Get the widget types for a context.
Definition: widgets.php:130
elgg_entity_gatekeeper($guid, $type=null, $subtype=null)
Can the viewer see this entity?
foreach($widgets as $column_widgets) $result
Definition: add_panel.php:43
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: pageowner.php:259
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:81
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
Definition: elgglib.php:168
$class
Definition: field.php:29
elgg_get_widgets($owner_guid, $context)
Get widgets for a particular context.
Definition: widgets.php:23
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg_view_module($type, $title, $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:1198
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:238
elgg echo
Translates a string.
Definition: languages.js:43
elgg_ajax_gatekeeper()
Require that the current request be an XHR.
$owner_guid
Definition: add_panel.php:20
$owner
Definition: add_panel.php:23
if($guid===false) $widget
Definition: add.php:30
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
$widgets
Definition: add_panel.php:27
$vars['type']
Definition: save.php:11
$handler
Definition: add.php:7
if(elgg_view_exists("plugins/{$plugin_id}/settings")) $description
Definition: full.php:179
$current_handlers
Definition: add_panel.php:36
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87