aboutsummaryrefslogtreecommitdiff
path: root/actions/widgets/add.php
blob: 33a818e549a91592c5c802337a1c0db5793d6586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
 * Elgg widget add action
 *
 * @package Elgg.Core
 * @subpackage Widgets.Management
 */

$user_guid = get_input('user');
$handler = get_input('handler');
$context = get_input('context');
$column = get_input('column', 1);

$guid = false;
if (!empty($user_guid)) {
	$user = get_entity($user_guid);
	if ($user && $user->canEdit()) {
		$guid = elgg_create_widget($user->getGUID(), $handler);
		if ($guid) {
			$widget = get_entity($guid);
			elgg_move_widget($widget, $context, $column, 0);

			// send widget html for insertion
			echo elgg_view_entity($widget);

			system_message(elgg_echo('widgets:add:success'));
			forward(REFERER);
		}
	}
}

register_error(elgg_echo('widgets:add:failure'));
forward(REFERER);