[commits] [Wiki] changed: CustomizingPreferencesH5
Wiki Guest
wikiguest at horde.org
Thu Mar 6 08:38:23 UTC 2014
guest [194.95.66.21] Thu, 06 Mar 2014 08:38:23 +0000
Modified page: http://wiki.horde.org/CustomizingPreferencesH5
New Revision: 3
Change log: example for kronotlith/search_sources
@@ -20,4 +20,44 @@
<code type="php">
<?PHP
$_prefs['search_sources']['value'] = '["favourites"]';
</code>
+
+++ Hooks
+
+You can provide default values by hooks, which are little PHP functions.
+
+Since Horde4 hooks are organized in classes, e.g.
{{config/hooks.php}} uses {{class Horde_Hooks}}, whereas
{{kronolith/config/hooks.php}} uses {{class Kronolith_Hooks}}. See
{{config/hooks.php}} for a description of hooks.
+
+For instance to automatically prepare Kronolith's {{search_sources}}
with all address books the user has access to:
+
+Enable the hook in the local prefs.php {{kronolith/config/prefs.local.php}}:
+<?PHP
+$_prefs['search_sources']['hook'] = true;
+</code>
+
+And add to {{kronolith/config/hooks.php}}:
+<code type="php">
+<?PHP
+class Kronolith_Hooks
+{
+ public function prefs_init($pref, $value, $username, $scope_ob)
+ {
+ if (is_null($username)) { // not logged in
+ return $value;
+ }
+
+ switch ($pref) {
+ case 'search_sources': // enable all sources by default
+ if($value == '') {
+ $sources = $GLOBALS['registry']->call('contacts/sources');
+ $value = json_encode(array_keys($sources));
+ $scope_ob->set($pref, $value);
+ $scope_ob->setDirty($pref, true);
+ }
+ return $value;
+ }
+ }
+}
+</code>
+
+
More information about the commits
mailing list