Index: branches/salvatoreingala/Gadgets/backend/Gadget.php |
— | — | @@ -648,6 +648,8 @@ |
649 | 649 | * Sets the description of preferences for this gadget. If the given array is not valid, |
650 | 650 | * then internal preference description is set to null. |
651 | 651 | * |
| 652 | + * Invalidates any previous preference value set with setPrefs(). |
| 653 | + * |
652 | 654 | * @param $prefsDescription mixed an array with new preferences description, or null. |
653 | 655 | * |
654 | 656 | */ |
— | — | @@ -657,6 +659,9 @@ |
658 | 660 | } else { |
659 | 661 | $this->prefsDescription = null; |
660 | 662 | } |
| 663 | + |
| 664 | + //Any previously set of preferences has no meaning now, set back to null |
| 665 | + $this->preferences = null; |
661 | 666 | } |
662 | 667 | |
663 | 668 | //Check if a preference is valid, according to description |
Index: branches/salvatoreingala/Gadgets/backend/GadgetHooks.php |
— | — | @@ -236,11 +236,18 @@ |
237 | 237 | } |
238 | 238 | |
239 | 239 | foreach ( $gadgets as $gadget ) { |
240 | | - if ( $gadget->getPrefs() !== null ) { |
241 | | - //TODO: should remove prefs that equal their default |
242 | | - |
243 | | - $prefsSerialized = serialize( $gadget->getPrefs() ); |
244 | | - $options["gadget-{$gadget->getName()}-config"] = $prefsSerialized; |
| 240 | + $prefs = $gadget->getPrefs(); |
| 241 | + if ( $prefs !== null ) { |
| 242 | + $prefsDescription = $gadget->getPrefsDescription(); |
| 243 | + |
| 244 | + //Remove preferences that equal their default |
| 245 | + foreach ( $prefs as $prefName => $value ) { |
| 246 | + if ( $prefsDescription['fields'][$prefName]['default'] === $value ) { |
| 247 | + unset( $prefs[$prefName] ); |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + $options["gadget-{$gadget->getName()}-config"] = serialize( $prefs ); |
245 | 252 | } |
246 | 253 | } |
247 | 254 | |