aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-20 14:33:17 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-20 14:33:17 +0000
commit95c79a67493521d2d9761fde60ccfbf2af48ce87 (patch)
tree57d7652f060a968efab7a6a6842d160bf0c73e5d /engine
parent4dcea7b5aa7b6a597a5d2d086f99dee6f57f9004 (diff)
downloadelgg-95c79a67493521d2d9761fde60ccfbf2af48ce87.tar.gz
elgg-95c79a67493521d2d9761fde60ccfbf2af48ce87.tar.bz2
moved save widget settings function to ElggWidget
git-svn-id: http://code.elgg.org/elgg/trunk@7383 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/classes/ElggWidget.php45
-rw-r--r--engine/lib/widgets.php43
2 files changed, 47 insertions, 41 deletions
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', <widget handler identifier>. 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
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index f5b473fd9..4a879e1ee 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -58,7 +58,7 @@ function elgg_get_widgets($user_guid, $context) {
* @return int|false Widget GUID or false on failure
* @since 1.8
*/
-function elgg_create_widget($owner_guid, $handler, $access_id = null) {
+function elgg_create_widget($owner_guid, $handler, $context, $access_id = null) {
if (empty($owner_guid) || empty($handler) || !elgg_is_widget_type($handler)) {
return false;
}
@@ -83,51 +83,12 @@ function elgg_create_widget($owner_guid, $handler, $access_id = null) {
// private settings cannot be set until ElggWidget saved
$widget->handler = $handler;
+ $widget->context = $context;
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 widget layout
*
* Triggers a 'permissions_check', 'widget_layout' plugin hook