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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:19:24
Script start
Timing: Jan 18 2025 11:19:24
Module start 'layout'
Timing: Jan 18 2025 11:19:24
Module start 'content'
Timing: Jan 18 2025 11:19:24
Module end 'content'
Timing: Jan 18 2025 11:19:24
Script end

Main resources:

Total runtime0.0159 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 587.9141152.6250
Module start 'layout' 0.00580.0028 740.539139.4453
Module start 'content' 0.00850.0052 779.984497.4453
Module end 'content' 0.01370.0021 877.429742.3047
Script end 0.0158  919.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002817.4703140.0002
Check MTime0.00127.6955140.0001
Mysql Total
Database connection0.00074.136010.0007
Mysqli_queries0.002213.822230.0007
Looping result0.00000.088610.0000
Template Total0.001811.110.0018
Template load0.00095.523210.0009
Template processing0.00095.497710.0009
Override
Cache load0.00063.948410.0006
General
dbfile0.00042.543280.0001
String conversion0.00000.054040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs