[development] Actions progress
James Walker
walkah at walkah.net
Fri May 25 13:13:20 UTC 2007
On 5/24/07 4:56 PM, John VanDyk wrote:
> Here's a progress report on actions-in-core.
>
> Actions now have a new architecture. Instead of a single function, an
> action now consists of several functions.
>
> 1. An implementation of hook_actions_info(). In this hook, an action is
> described just like it was in the 'metadata' operation of the previous
> action architecture. And supported hooks are declared:
>
> function node_action_info() {
> return array(
> 'node_make_sticky_action' => array(
> 'type' => 'node',
> 'description' => t('Make node sticky'),
> 'configurable' => FALSE,
> 'hooks' => array(
> 'nodeapi' => array('delete','insert','update', 'view'),
> 'comment' => array('delete','insert','update', 'view'),
> ),
> ),
> );
> }
>
> Batchability has been dropped. Instead of actions declaring themselves
> batchable and a node_save() being done at the end of the batch, "Save
> node" is now a separate action.
>
> 2. The action itself:
>
> /**
> * Implementation of a Drupal action.
> * Sets the sticky-at-top-of-list property of a node to 1.
> */
> function node_make_sticky_action($context = array(), &$node) {
> $node->sticky = 1;
> $node->revision = 0;
> watchdog('action', t('Made node id %id sticky', array('%id' =>
> $node->nid)));
> }
>
> 3. If the action is a configurable action such as the "Display a message
> to the user" action, it needs to define a form, validate, and submit
> function. The submit function is responsible for returning a keyed array
> with parameters that will be stored and used when the action is fired.
> E.g., (validate function not shown):
>
> function system_message_action_form($edit) {
> $form['message'] = array(
> '#type' => 'textarea',
> '#title' => t('Message'),
> '#default_value' => isset($edit['message']) ? $edit['message'] :
> '',
> '#required' => TRUE,
> '#rows' => '8',
> '#description' => t('The message to be displayed to the current
> user. You may include the following variables: %site_name, %username,
> %node_url, %node_type, %title, %teaser, %body.'),
> );
> return $form;
> }
>
> function system_message_action_form_submit($form_id, $form_values) {
> return array('message' => $form_values['message']);
> }
>
> The HEAD version of actions is now stable enough to demonstrate the
> assignment of actions to various hooks. It runs on Drupal 5 currently. I
> encourage you to check it out and give me feedback on
> http://groups.drupal.org/actions or just in an email.
>
> Hopefully we can have a facade action that hooks up to any Drupal form
> id, and uses drupal_execute() to fire the action. That would mean many
> Drupal forms become "scriptable" automatically.
Dear John,
You rock.
Love,
James
--
James Walker :: http://walkah.net/ :: xmpp:walkah at walkah.net
More information about the development
mailing list