Opened 3 years ago

Closed 3 years ago

#1486914 closed Bugs (fixed)

Inconsistent 'abort' argument handling

Reported by: alec Owned by: alec
Priority: 5 Milestone: 0.5-beta
Component: Plugin API Version: 0.4-stable
Severity: normal Keywords:
Cc:

Description

Hook's 'abort' argument handling looks a little bit confusing. Let's check 'group_create' hook:

  $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
  if (!$plugin['abort'])
    $created = $CONTACTS->create_group($plugin['name']);
}
  if ($created && $OUTPUT->ajax_call) {
    $created['source'] = $source;
    $OUTPUT->command('insert_contact_group', $created);
  }                                         
  else if (!$created) {
    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error');
  }

What if I want to skip create_group(), but I want to execute code which is executed when $created=true? E.g. I have an own addressbook plugin with groups handling, so I don't want to use $CONTACTS->create_group(), but I want to insert group record in the UI. Do I need to call output commands from the plugin or we could change this behaviour. This is an example, the problem is generic.

Change History (7)

comment:1 Changed 3 years ago by thomasb

Abort means aborting the currect action and this IMO is consistently implemented over all plugin hooks.

What you're requesting is more something like a preventdefault argument.
This looks like a feature request to me, isn't it?

comment:2 Changed 3 years ago by alec

Maybe so, but if plugin author want to do abort in your meaning, he can just do:

$OUTPUT->send(); // or exit();

or something like that. That's because I think would be better to redefine 'abort' behaviour than adding 'preventdefault' feature. As you see in group_create example aborting doesn't prevent from displaying error message.

comment:3 Changed 3 years ago by thomasb

OK, you convinced me. Our abort is actually a preventdefault feature. So do you want to rename it or what is your suggestion?

comment:4 Changed 3 years ago by alec

I'm not sure. In this case we could leave 'abort' as is and add 'result' property.

  $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source));
  if (!$plugin['abort'])
    $created = $CONTACTS->create_group($plugin['name']);
  else
    $created = $plugin['result'];

So, it causes that 'abort' skips only the main action, here it is

$created = $CONTACTS->create_group($plugin['name']);

and the code after that can proceed.

comment:5 Changed 3 years ago by thomasb

Your proposition sound good to me.

comment:6 Changed 3 years ago by alec

  • Milestone changed from 0.4.2 to 0.5-beta
  • Owner set to alec

comment:7 Changed 3 years ago by alec

  • Resolution set to fixed
  • Status changed from new to closed

Implemented in [ce92ba76].

Note: See TracTickets for help on using tickets.