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