From 95c79a67493521d2d9761fde60ccfbf2af48ce87 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 20 Nov 2010 14:33:17 +0000 Subject: moved save widget settings function to ElggWidget git-svn-id: http://code.elgg.org/elgg/trunk@7383 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggWidget.php | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'engine/classes') diff --git a/engine/classes/ElggWidget.php b/engine/classes/ElggWidget.php index e1c975777..1622aa5b3 100644 --- a/engine/classes/ElggWidget.php +++ b/engine/classes/ElggWidget.php @@ -144,4 +144,49 @@ class ElggWidget extends ElggObject { } $this->column = $column; } + + /** + * Saves the widget's settings + * + * Plugins can override the save mechanism using the plugin hook: + * 'widget_settings', . The widget and + * the parameters are passed. The plugin hook handler should return + * true to indicate that it has successfully saved the settings. + * + * @warning The values in the parameter array cannot be arrays + * + * @param array $params An array of name => value parameters + * + * @return bool + * @since 1.8.0 + */ + public function saveSettings($params) { + if (!$this->canEdit()) { + return false; + } + + // plugin hook handlers should return true to indicate the settings have + // been saved so that default code does not run + $hook_params = array( + 'widget' => $this, + 'params' => $params + ); + if (elgg_trigger_plugin_hook('widget_settings', $this->handler, $hook_params, false) == true) { + return true; + } + + if (is_array($params) && count($params) > 0) { + foreach ($params as $name => $value) { + if (is_array($value)) { + // private settings cannot handle arrays + return false; + } else { + $this->$name = $value; + } + } + $this->save(); + } + + return true; + } } \ No newline at end of file -- cgit v1.2.3