Elgg  Version master
add_panel.php
Go to the documentation of this file.
1 <?php
12 
13 // restoring context stack
14 $context_stack = get_input('context_stack');
15 if (!empty($context_stack) && is_array($context_stack)) {
17 }
18 
19 elgg_import_esm('resources/widgets/add_panel');
20 
21 $context = (string) elgg_extract('context', $vars, get_input('context'));
22 $owner_guid = (int) elgg_extract('owner_guid', $vars, (int) get_input('owner_guid'));
23 $new_widget_column = elgg_extract('new_widget_column', $vars, get_input('new_widget_column'));
24 $new_widget_position = elgg_extract('new_widget_position', $vars, get_input('new_widget_position'));
25 
27 
29 
32  'context' => $context,
33  'container' => $owner,
34 ]);
35 uasort($widget_types, function ($a, $b) {
36  return strcmp($a->name, $b->name);
37 });
38 
40 foreach ($widgets as $column_widgets) {
41  foreach ($column_widgets as $widget) {
42  $current_handlers[] = $widget->handler;
43  }
44 }
45 
47  'class' => 'elgg-text-help',
48 ], elgg_echo('widgets:add:description'));
49 
51 foreach ($widget_types as $handler => $widget_type) {
52  $class = [];
53  // check if widget added and only one instance allowed
54  if (!$widget_type->multiple && in_array($handler, $current_handlers)) {
55  $class[] = 'elgg-state-unavailable';
56  } else {
57  $class[] = 'elgg-state-available';
58  }
59 
60  $class[] = $widget_type->multiple ? 'elgg-widget-multiple' : 'elgg-widget-single';
61 
62  $action = '<div class="elgg-widgets-add-actions">';
63  if (!$widget_type->multiple) {
64  $action .= elgg_format_element('span', ['class' => 'elgg-quiet'], elgg_echo('widget:unavailable'));
65  }
66 
67  $action .= elgg_view('output/url', [
68  'class' => ['elgg-button', 'elgg-button-submit', 'elgg-size-small'],
69  'text' => elgg_echo('add'),
70  'href' => elgg_generate_action_url('widgets/add', [
71  'handler' => $handler,
72  'page_owner_guid' => $owner_guid,
73  'context' => $context,
74  'show_access' => elgg_extract('show_access', $vars, get_input('show_access')),
75  'default_widgets' => elgg_in_context('default_widgets'),
76  'new_widget_column' => $new_widget_column,
77  'new_widget_position' => $new_widget_position,
78  ]),
79  ]);
80  $action .= '</div>';
81 
82  $description = elgg_format_element('div', ['class' => 'elgg-loud'], $widget_type->name);
83 
84  if ($widget_type->description) {
85  $description .= elgg_format_element('div', ['class' => 'elgg-quiet'], $widget_type->description);
86  }
87 
89  'class' => 'elgg-widgets-add-description',
90  ], $description);
91 
92  $item_content = $description . $action;
93 
95  'class' => $class,
96  'data-elgg-widget-type' => $handler,
97  ], $item_content);
98 }
99 
101 
102 $search_box = elgg_view('input/text', [
103  'name' => 'widget_search',
104  'title' => elgg_echo('search'),
105  'placeholder' => elgg_echo('search'),
106 ]);
107 
108 echo elgg_view_module('info', elgg_echo('widgets:add'), $result, [
109  'class' => 'elgg-widgets-add-panel',
110  'menu' => $search_box,
111 ]);
$vars
Definition: theme.php:3
if($guid===false) $widget
Definition: add.php:31
$handler
Definition: add.php:7
foreach($widgets as $column_widgets) $result
Definition: add_panel.php:46
$owner_guid
Definition: add_panel.php:22
$widgets
Definition: add_panel.php:30
$context_stack
Definition: add_panel.php:14
$new_widget_column
Definition: add_panel.php:23
$search_box
Definition: add_panel.php:102
$owner
Definition: add_panel.php:26
$widget_types
Definition: add_panel.php:31
$context
Definition: add_panel.php:21
$new_widget_position
Definition: add_panel.php:24
$list_items
Definition: add_panel.php:50
$current_handlers
Definition: add_panel.php:39
$class
Definition: summary.php:44
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: context.php:99
elgg_in_context(string $context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:246
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_get_widget_types(string|array $context='')
Get the widget types for a context.
Definition: widgets.php:112
elgg_get_widgets(int $owner_guid, string $context)
Elgg widgets library.
Definition: widgets.php:20
elgg_import_esm(string $name)
Helper functions for external files like css/js.
elgg_entity_gatekeeper(int $guid, ?string $type=null, ?string $subtype=null, bool $validate_can_edit=false)
Can the viewer see this entity?
Definition: gatekeepers.php:99
elgg_ajax_gatekeeper()
Require that the current request be an XHR.
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:922
elgg_view(string $view, array $vars=[], string $viewtype='')
Return a parsed view.
Definition: views.php:156
elgg_format_element(string $tag_name, array $attributes=[], string $text='', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
elgg_set_page_owner_guid(int $guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:34
$description
Definition: record.php:15
$action
Definition: subscribe.php:11