save.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Elgg save widget settings action
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Widgets.Management
  7. *
  8. * @uses int $_REQUEST['guid'] The guid of the widget to save
  9. * @uses array $_REQUEST['params'] An array of params to set on the widget.
  10. * @uses int $_REQUEST['default_widgets'] Flag for if these settings are for default wigets.
  11. * @uses string $_REQUEST['context'] An optional context of the widget. Used to return
  12. * the correct output if widget content changes
  13. * depending on context.
  14. * @uses string $_REQUEST['title'] Optional title for the widget
  15. *
  16. */
  17. $guid = get_input('guid');
  18. $params = get_input('params');
  19. $default_widgets = get_input('default_widgets', 0);
  20. $context = get_input('context');
  21. $title = get_input('title');
  22. if ($default_widgets) {
  23. elgg_push_context('default_widgets');
  24. }
  25. elgg_push_context('widgets');
  26. $widget = get_entity($guid);
  27. if ($widget && $widget->saveSettings($params)) {
  28. if ($title && $title != $widget->title) {
  29. $widget->title = $title;
  30. $widget->save();
  31. }
  32. elgg_set_page_owner_guid($widget->getContainerGUID());
  33. if ($context) {
  34. elgg_push_context($context);
  35. }
  36. echo elgg_view('object/widget/elements/content', ['entity' => $widget]);
  37. if ($context) {
  38. elgg_pop_context();
  39. }
  40. } else {
  41. register_error(elgg_echo('widgets:save:failure'));
  42. }
  43. // widgets context
  44. elgg_pop_context();
  45. if ($default_widgets) {
  46. elgg_pop_context();
  47. }
  48. forward(REFERER);