Roundcube Community Forum

 

Plugin : Add custom form

Started by Antho, January 25, 2011, 04:37:30 AM

Previous topic - Next topic

Antho

Hello,

I'm trying to add a custom form under the header table when viewing (or previewing) a message. I managed to display an area using :

$this->add_hook('template_object_messageheaders', array($this, 'generate_html')); and adding a simple div tag.

It worked for the displaying of a message but not for the previewing and I don't understand why.

Also, I'd like to customize the display of the message list by adding attributes from the header of the message. It seems I'll need to use the "messages_list" hook but I wonder how to add those custom columns in the table and if it is possible to do so just using plugins.

Thanks a lot,
Antho

Antho

I still don't have figured out how to hook the preview panel but I think a template-based solution would be much better.

So I have an other question : how to display a template at the right place ?
I try to register a handler at the right moment (after an existing container has been parsed) to send my custom template but it doesn't work.

rosali

render_page hook is your friend.

Plugin_Hooks ? Roundcube Webmail

It holds the template name without file extension in the passed array:


...in the init section of the plugin:

$this->add_hook('render_page', array($this, 'associated_render_page'));  

...in the methods section of the plugin:

function associated_render_page($args){
  if($args['template'] == 'messagepreview'){
    $content = $args['content'];
    // now modify $content for your needs
    $content = 'hmm... what does he want?';
    $args['content'] = $content;
  }
  // and pass it ...
  return $args;
}


____ EDIT TYPOS ____
Regards,
Rosali

Antho

Ah, now I really understand how the plugin system works, thanks !

Instead of hard coding the content, it's possible to load a custom template and register a handler for the new elements :

// File : my_plugin.php
function init () {
  $this->add_hook('render_page', array($this, 'associated_render_page'));
  $this->register_handler('plugin.body', array($this, 'gen_html'));
}

function associated_render_page($args){
  if($args['template'] == 'messagepreview'){
    $args['template'] = 'my_template';
    $rcmail = rcmail::get_instance();
    $rcmail->output->send('my_plugin.my_template', true);
  }
  return $args;
}

function gen_html ()
{
  $content = 'Foo';
  return $content;
}

my_template is made of the original 'messagepreview.html' and some custom elements :

// File : my_plugin/skins/default/templates/my_template.html
// [...]



// [/...]

I put the code here because I didn't see any plugin using this method to add elements in an existing page. Please, tell me if I do anything wrong.

Antho

It seems the solution I posted doesn't work that well..
When I try to change the compose template, it displays the new elements at the right place but I can't send e-mails any more.


if ($args['template'] == 'compose') {
    // replace the default template with a new one which contains the new UI elements
    $rcmail->output->send('myplugin.mycompose');
}


Apparently, the new template overwrites the default behavior of the compose template and when I click on the 'Send now' button, there is an endless loading message ("Sending message...").

Sorry if I've missed something obvious, maybe I was doing wrong since the beginning using templates to add elements in the user interface.

- What is the best way to add a
element between the subject input in php ?
- Is it possible to keep the default behavior of the compose.html template when you replace it by another template ?

Thanks