Roundcube Community Forum

 

Beginners Question how to add preferences section

Started by mad4linux, May 10, 2015, 12:25:27 PM

Previous topic - Next topic

mad4linux

I've just started developping my first plugin for roundcube. It shll be a simple interface for our staff to activate / deactivate their vacation message.

I'd like to add another section to the users preferences. so far I've tried to add an item to preferences_sections_list and added a dummy preferences_list, too. to my understanding of the documentation and also the code from the enigma plugin, roundcube should now display my section. But it doesn't. I'm obviously missing something, but can't fiure out what it might be. Any hints would be appreciated.

I know that my code is executed, because inserting an print_r($param_list); actually shows the modified preferences_sections_list

My current relevant code looks like this:

public function init()  {
//register to settings hooks
$this->add_hook('preferences_sections_list', array($this, 'preferences_sections_list'));
$this->add_hook('preferences_list', array($this, 'preferences_list'));
$this->add_hook('preferences_save', array($this, 'preferences_save'));
}

function preferences_sections_list($param_list)  {
$param_list['list']['exim_vacation'] = array(
'id' => 'exim_vacation', 'section' => $this->gettext('settings_tab'),
); //works, checked
                return $param_list;
}

function preferences_list($param_list) {
if ($param_liste['section'] != 'exim_vacation') {
return $param_list;
}
$param_list['blocks']['main']['name'] = $this->gettext('settings');
return $param_list;
}

function preferences_save($save_params) {
if ($save_params['section'] == 'exim_vacation') {
$save_params['prefs'] = array( );
}
return $save_params;
}

}



mad4linux

Replying myself for the sake of documentation:

I've now added one option to my preferences_list and the section is now displayed.
So it seems, that only sections with options available are displayed.
So my functions_list() looks now like this. Doesn't do anything useful, but with the $param_list['blocks']['main']['options']['enable_vacation'] line added, the settings section is now displayed :

function preferences_list($param_list) {
if ($param_list['section'] != 'exim_vacation') {
return $param_list;
}
$param_list['blocks']['main']['name'] = $this->gettext('settings');

$field_id = 'rcmfd_enable_exim_vacation';
$param_list['blocks']['main']['options']['enable_vacation'] = array(
'title'   => html::label($field_id, $this->gettext('send_msg')),
'content' => 'dummy' /* $input */);
return $param_list;
}