From 3b46665b3f4ee10e9d2778033ea7180cca7571eb Mon Sep 17 00:00:00 2001 From: cash Date: Fri, 19 Nov 2010 20:43:48 +0000 Subject: saving widget settings git-svn-id: http://code.elgg.org/elgg/trunk@7350 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/widgets.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'engine/lib/widgets.php') diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php index 92d022913..1396a9d8f 100644 --- a/engine/lib/widgets.php +++ b/engine/lib/widgets.php @@ -85,6 +85,45 @@ function elgg_create_widget($owner_guid, $handler, $access_id = null) { return $widget->getGUID(); } +/** + * Saves a widget's settings + * + * Plugins can override this save function by defining a function of the name + * "elgg_save_{$widget->handler}_widget_settings" that takes the widget object + * and the parameter array as arguments + * + * @param int $guid The GUID of the widget + * @param array $params An array of name => value parameters + * @return bool + * @since 1.8.0 + */ +function elgg_save_widget_settings($guid, $params) { + $widget = get_entity($guid); + if (!$widget || !$widget->canEdit()) { + return false; + } + + // check if a plugin is overriding the save function + $function = "elgg_save_{$widget->handler}_widget_settings"; + if (is_callable($function)) { + return $function($widget, $params); + } + + if (is_array($params) && count($params) > 0) { + foreach ($params as $name => $value) { + if (is_array($value)) { + // private settings cannot handle arrays + return false; + } else { + $widget->$name = $value; + } + } + $widget->save(); + } + + return true; +} + /** * Can the user edit the widgets * @@ -371,8 +410,10 @@ function get_widget_types() { * @param array $params An array of name => value parameters * * @return bool + * @deprecated 1.8 */ function save_widget_info($widget_guid, $params) { + elgg_deprecated_notice("save_widget_info() is deprecated for elgg_save_widget_settings", 1.8); if ($widget = get_entity($widget_guid)) { $subtype = $widget->getSubtype(); @@ -428,8 +469,10 @@ function save_widget_info($widget_guid, $params) { * @param int $owner Owner guid * * @return void + * @deprecated 1.8 */ function reorder_widgets_from_panel($panelstring1, $panelstring2, $panelstring3, $context, $owner) { + elgg_deprecated_notice("reorder_widgets_from_panel() is deprecated", 1.8); $return = true; $mainwidgets = explode('::', $panelstring1); @@ -597,7 +640,6 @@ function widget_run_once() { * @return void */ function widgets_init() { - register_action('widgets/reorder'); register_action('widgets/save'); register_action('widgets/add'); register_action('widgets/move'); -- cgit v1.2.3