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

eZ debug

Timing: Jan 18 2025 04:30:39
Script start
Timing: Jan 18 2025 04:30:39
Module start 'content'
Timing: Jan 18 2025 04:30:40
Module end 'content'
Timing: Jan 18 2025 04:30:41
Script end

Main resources:

Total runtime1.1514 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.8438180.8359
Module start 'content' 0.00801.0003 769.6797629.1328
Module end 'content' 1.00830.1430 1,398.8125341.0625
Script end 1.1513  1,739.8750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00470.4067210.0002
Check MTime0.00150.1325210.0001
Mysql Total
Database connection0.00090.075610.0009
Mysqli_queries1.066092.58602080.0051
Looping result0.00210.17902060.0000
Template Total1.106496.120.5532
Template load0.00280.241520.0014
Template processing1.103695.853520.5518
Template load and register function0.00020.015710.0002
states
state_id_array0.00160.136810.0016
state_identifier_array0.00190.164320.0009
Override
Cache load0.00240.2119480.0001
Sytem overhead
Fetch class attribute can translate value0.00130.115240.0003
Fetch class attribute name0.00130.114380.0002
XML
Image XML parsing0.00110.093940.0003
class_abstraction
Instantiating content class attribute0.00000.0023100.0000
General
dbfile0.00230.1984270.0001
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs