I'm trying to implement actions - trigger support in my module (not standard NODE / USER / TAXONOMY actions, but my custom ones). Can anyone point me to some documentation which describes this in details, or perhaps give me a hand with this problem. Thanks in advance.

I understand that

hook_hook_info()

is responsible for letting the engine know about available actions, and I assume that

hook_action_info()

is responsible for providing triggers, but there is no info about this hook in api doc.

sorry for my English.

Comments

bboldi’s picture

here is the description for hook_action_info

http://drupal.org/files/issues/hook_action_info_d6.patch

----------------------------------------
Boldizsár Bednárik ing.
http://www.bboldi.com

criznach’s picture

Creating Actions is fairly straight forward and works as documented here:
http://drupal.org/node/172152

Creating triggers is definitely possible, but not very well documented, and I'd recommend looking at the simplest of the existing trigger implementations - maybe node.module...

You may find some triggers help in this talk...
http://www.archive.org/details/DrupalconBoston2008-TriggersAndActionsAnd...

Later,
Chris.

http://www.trailheadinteractive.com

bboldi’s picture

Thanks man!

----------------------------------------
Boldizsár Bednárik ing.
http://www.bboldi.com

bboldi’s picture

Here is a sample module code I wrote to demonstrate the method for defining new actions and triggers and join them together. I hope it will help the community ;)

This code will add a new tab to the trigger page named "action trigger sample", it's simple and understundable... i hope...


/**
 * @author Bednarik Boldizsar
 * @copyright 2008
 */

function atsample_init()
{
	// fire the trigger
	
	_atsample_invoke_every_page_trigger();
	_atsample_invoke_random_page_trigger();
}

function _atsample_invoke_every_page_trigger()
{
	$aids = _trigger_get_hook_aids('atsample', 'on_every_page');
	
	foreach ($aids as $aid => $action_info) {
		
		$message = 'EVERY PAGE Hello World!';
		actions_do($aid,$message);
	}

}

function _atsample_invoke_random_page_trigger()
{
	function make_seed()
	{
	  list($usec, $sec) = explode(' ', microtime());
	  return (float) $sec + ((float) $usec * 100000);
	}

	srand(make_seed());
	$randval = rand();
	
	if(($randval % 3) == 0)
	{	
 		$aids = _trigger_get_hook_aids('atsample', 'on_random_page');
  		
  		foreach ($aids as $aid => $action_info) {
			$message = 'RANDOM Hello World!';
  			actions_do($aid,$message);
		}
	}
}

function atsample_hook_info() {
  return array(
    'atsample' => array(
      'atsample' => array(
        'on_every_page' => array(
          'runs when' => t('On every page'),
        ),
        'on_random_page' => array(
          'runs when' => t('On random pages'),
        ),
      ),
    ),
  );
}

/**
 * Implementation of hook_action_info().
 */
function atsample_action_info() {
  return array(
    'atsample_show_message' => array(
      'description' => t('Show a Hello World message!'),
      'type' => 'atsample',
      'configurable' => false,
      'hooks' => array(
        'atsample' => array('on_every_page', 'on_random_page'),
      )
    ),
  );
}

/**
 * The action callback function
 */ 

function atsample_show_message(&$object,$context)
{
	drupal_set_message($object);
}

----------------------------------------
Boldizsár Bednárik ing.
http://www.bboldi.com

anotherdave’s picture

HI, where should this code be placed?

In a custom module, or in actions.inc or somewhere else entirely?

Thanks
Dave

bboldi’s picture

it's a sample custom module.

anotherdave’s picture

Wow, just reread this - you'd think I would've copped that from where you said "Here is a sample module code I wrote"! Cheers man, sorry for the silly question!

Dave