Forums / Developer / module hook

module hook

Author Message

Marko Žmak

Tuesday 22 December 2009 1:18:29 pm

Is there a way to hook a PHP function to execute it at the end of a module execution? I'm looking for a general way to accomplish this. For example I would like to hook my PHP functions to this modules and functions:

content/tipafriend
user/register

but also to some other modules and function. So this is why I'm looking for a general way to do this, and not for specific module hooks. Is it possible?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Bruce Morrison

Wednesday 23 December 2009 12:54:18 am

Hi Marko

You can currently add a workflow to user/register using a post/pre publish trigger.

You may be able to add PHP code by executing the required module from a custom one. Have a look at how user/register works (it's basically a wrapper for content/edit) and layout/set ( a wrapper for content/view ).

Also eZModule documentation was recently updated: http://pubsvn.ez.no/doxygen/trunk/html/classeZModule.html

HTH

cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Marko Žmak

Wednesday 23 December 2009 2:31:05 am

Thanks fot the answer Bruce. I'm looking for a general solution for this that works with all modules. and your suggestion ("You may be able to add PHP code by executing the required module from a custom one") could be a step forward. So the next question is...

How can I do this:

- for any exsisting module that I want, create my own code which does everything that the module originally does, but also executes some ektra code. Can this be achieved using extensions, and how?

- I would also like that this feature stays compatible with the rest of the eZ so that I don't have to call new custom modules but that everything works with existing modules (i.e. content/edit, content/tipafriend, user/register ...). So this brings another question: Can modules be overriden in extensions and how?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Bayron Guevara

Monday 01 February 2010 11:53:35 am

I think that Ez Publish should be more flexible respect to the hook implementation, currently if you only want to add a new functionality to a existing module/view, you need to create a new module and then since here call to first. This is deficient in terms of manteinance and expandability, because you would have to change all the links using the module to point to the new one. Currently EzPublish implements hooks in the module level, but the view must include code for this through the eZModule::runHooks method, also Ez Publish should allow us to run hooks in any module/view. Some people have said me about the kernel class override, but what happen if the view don't use classes, for example the user/preferences.

I suggest the following: Create another type of extension. Where you define the module/view, the method to execute, type of hook (pre or post) and the priority (the execution order). The definition file would be something like:

<?php 
$eZModulesHooksArray[] = 
array( 'view' => <module/view>,
          'class' => '<Class Name>',
          'method' => <Method Name>,
          'script' => <Path to Class definition>,
          'type' => <pre | post>,
          'priority' => <position in stack execution> );
?>

Ez Publish then should automatically register this hooks for the active extensions and execute them implicitly for all module views. A similiar implementation are the WordPress hooks: http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters

I think other developers find the same problems and agree with me about a better implementation. Maybe a Ez Publish crew hear us and it will be implemented in a near future.

Web Developer & Modern Philosopher
Visit http://www.laprensa.hn, http://www.diez.hn, http://www.estilo.hn

Gaetano Giunta

Tuesday 02 February 2010 2:11:58 pm

Instead of adding yet another feature, why not improve existing ones instead?

Triggers are sparse, but a great way for achieving this imho. they just need

- a lot more documentation on the workings of the action-related classes and their structure

- a lot more of them

Principal Consultant International Business
Member of the Community Project Board

eZ debug

Timing: Jan 17 2025 23:41:36
Script start
Timing: Jan 17 2025 23:41:36
Module start 'content'
Timing: Jan 17 2025 23:41:37
Module end 'content'
Timing: Jan 17 2025 23:41:37
Script end

Main resources:

Total runtime1.1184 sec
Peak memory usage4,096.0000 KB
Database Queries205

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0078 588.6719180.8516
Module start 'content' 0.00780.9818 769.5234673.3359
Module end 'content' 0.98960.1287 1,442.8594341.0859
Script end 1.1183  1,783.9453 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3396210.0002
Check MTime0.00140.1264210.0001
Mysql Total
Database connection0.00080.071610.0008
Mysqli_queries1.032692.32742050.0050
Looping result0.00220.19422030.0000
Template Total1.089897.420.5449
Template load0.00190.173220.0010
Template processing1.087997.273620.5439
Template load and register function0.00010.013210.0001
states
state_id_array0.00070.058510.0007
state_identifier_array0.00090.080320.0004
Override
Cache load0.00170.1496370.0000
Sytem overhead
Fetch class attribute can translate value0.00170.156350.0003
Fetch class attribute name0.00140.125690.0002
XML
Image XML parsing0.00250.219750.0005
class_abstraction
Instantiating content class attribute0.00010.0107100.0000
General
dbfile0.00470.4208480.0001
String conversion0.00000.000430.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
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
1content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 9

Time used to render debug report: 0.0002 secs