Forums / Developer / Creating a custom trigger

Creating a custom trigger

Author Message

Dmytro Tomilovskiy

Wednesday 19 July 2006 11:05:40 am

Greetings everyone.

I am trying to create a custom trigger that will run a workflow event before a content object is removed.

The following code was added to /kernel/classes/operation_defenition.php

$OperationList['remove'] = array ( 'name' => 'remove', 
				     	     'default_call_method' => array('kernel/content/ezcontentoperationcollection.php', 
                                                                  'class' => 'eZContentOperationCollection'), 
                                   'parameter_type' => 'standard', 
                                   'parameters' => array( array( 'name' => 'node_id', 
                                                                 'type' => 'integer', 
                                                                 'required' => true) ), 
                                   'keys' => array('node_id'), 
                                   'body' => array( array( 'type' => 'trigger', 
                                                           'name' => 'pre_remove', 
                                                           'keys' => array('object_id','version') ) )
					 ); 

The only thing I need to get executed is the actual trigger.

Now the following code was added to /kernel/content/removeobject.php


$operationResult = eZOperationHandler::execute( 'content', 'remove', array( 'node_id' => $contentNodeID ), null, TRUE); 

I also modified workflow.ini so the trigger shows up in <eZ_url>/trigger/list by adding

AvailableOperationList[]=content_remove

When I am trying to delete something $operationResult = NULL and therefore nothing happens - the workflow doesnt get executed.

What have I done wrong?

Kristof Coomans

Thursday 20 July 2006 1:58:06 am

Hello Dmytro

Use /kernel/content/operation_defenition.php instead of /kernel/classes/operation_defenition.php.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Dmytro Tomilovskiy

Thursday 20 July 2006 4:52:46 am

Greetings everyone.

I have noticed a couple of mistakes in my post:

1. operation_defenition.php is in kernel/content
2. the code that was added to operation_defenition.php is this

$OperationList['remove'] = array ( 'name' => 'remove', 
				     	     'default_call_method' => array('kernel/content/ezcontentoperationcollection.php', 
                                                                  'class' => 'eZContentOperationCollection'), 
                                   'parameter_type' => 'standard', 
                                   'parameters' => array( array( 'name' => 'object_id', 
                                                                 'type' => 'integer', 
                                                                 'required' => true) ), 
                                   'keys' => array('object_id'), 
                                   'body' => array( array( 'type' => 'trigger', 
                                                           'name' => 'pre_remove', 
                                                           'keys' => array('object_id','version') ) )
					 ); 

And one more thing. In removeobject.php the following line

$contentObjectID = $http->sessionVariable( 'ContentObjectID' );

Gives you something rather strange - %objectID'. Isnt it supposed to be smth like 157?

Thank you for your time.

Kristof Coomans

Tuesday 25 July 2006 10:10:50 am

 Isnt it supposed to be smth like 157?

Indeed it should be something like that. Strange.

I would recommend to move the code for the actual removal of the object to the operation as well (an entry of type "method" in the "body" array). An operation with only a trigger doesn't make much sense.

Which version of eZ publish are you using? Keep posting your code, then I can try to help you make it working.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Tuesday 25 July 2006 10:13:07 am

I haven't tried this contribution myself but it could be a useful example: http://ez.no/community/contribs/hacks/content_remove_workflow

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

nehal shah

Thursday 28 October 2010 6:36:56 am

Hi

I want to create new custom trigger.

So i want to know how can i view my trigger in the trigger list?

In which file i have to make changes, and please give me sample code of any custom trigger if possible.

Thank you

nehal shah

Thursday 28 October 2010 11:03:32 pm

Hi

Take a look at the question asked by Dmytro Tomiloyskiy, for craeting custom trigger he added code in to the kernel/content/operation_definition.php.

But my question is that how would he know that to go only that particular php file for add trigger,i cant understand where this would define, or how developer would know that he/she has to go with this specific file only?

Thank you