Elgg  Version master
add.php
Go to the documentation of this file.
1 <?php
6 $page_owner_guid = (int) get_input('page_owner_guid');
7 $handler = (string) get_input('handler');
8 $context = (string) get_input('context');
9 $show_access = (bool) get_input('show_access', true);
10 $column = (int) get_input('new_widget_column', 1);
11 $position = get_input('new_widget_position', 'top') === 'top' ? 0 : -1;
12 $default_widgets = (int) get_input('default_widgets', 0);
13 
15 
17 if (!$page_owner) {
18  return elgg_error_response(elgg_echo('widgets:add:failure'));
19 }
20 
22  // logged in user must be able to edit the layout to add a widget
23  return elgg_error_response(elgg_echo('widgets:add:failure'));
24 }
25 
27 if ($guid === false) {
28  return elgg_error_response(elgg_echo('widgets:add:failure'));
29 }
30 
32 
33 // position the widget
34 $widget->move($column, $position);
35 
37 
38 if ($default_widgets) {
39  $context_stack[] = 'default_widgets';
40 }
41 
42 $context_stack[] = 'widgets';
43 if ($context) {
45 }
46 
47 foreach ($context_stack as $ctx) {
48  elgg_push_context($ctx);
49 }
50 
52 
$context
Definition: add.php:8
$position
Definition: add.php:11
$default_widgets
Definition: add.php:12
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$column
Definition: add.php:10
elgg_can_edit_widget_layout(string $context, int $user_guid=0)
Can the user edit the widget layout.
Definition: widgets.php:50
elgg_set_page_owner_guid(int $guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:34
$context_stack
Definition: add.php:36
$show_access
Definition: add.php:9
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_create_widget(int $owner_guid, string $handler, string $context, int $access_id=null)
Create a new widget instance.
Definition: widgets.php:35
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
if(!$page_owner) if(!elgg_can_edit_widget_layout($context)) $guid
Definition: add.php:26
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:493
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$page_owner
Definition: add.php:16
if($guid===false) $widget
Definition: add.php:31
elgg_push_context(string $context)
Push a context onto the top of the stack.
Definition: context.php:52
if($context) foreach($context_stack as $ctx) $result
Definition: add.php:51
$page_owner_guid
Elgg widget add action.
Definition: add.php:6
$handler
Definition: add.php:7