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