Author Topic: Plugin : Add custom form  (Read 2519 times)

Offline Antho

  • Newbie
  • *
  • Posts: 8
Plugin : Add custom form
« on: January 25, 2011, 04:37:30 AM »
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 :

Code: [Select]
$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
« Last Edit: January 25, 2011, 05:28:13 AM by Antho »

Offline Antho

  • Newbie
  • *
  • Posts: 8
Plugin : Add custom form
« Reply #1 on: January 25, 2011, 07:37:53 AM »
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.

Offline rosali

  • Hero Member
  • *****
  • Posts: 2,533
Plugin : Add custom form
« Reply #2 on: January 25, 2011, 07:58:28 AM »
render_page hook is your friend.

Plugin_Hooks ? Roundcube Webmail

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

Code: [Select]

...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
__________________
MyRoundcube Project (commercial)

Offline Antho

  • Newbie
  • *
  • Posts: 8
Plugin : Add custom form
« Reply #3 on: January 25, 2011, 09:43:54 AM »
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 :

Code: [Select]
// 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 :

Code: [Select]
// 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.

Offline Antho

  • Newbie
  • *
  • Posts: 8
Plugin : Add custom form
« Reply #4 on: February 28, 2011, 10:21:02 AM »
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.

Code: [Select]

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