Forums / Developer / How to extend kernel classes and module's views ?

How to extend kernel classes and module's views ?

Author Message

H-Works Agency

Tuesday 28 August 2007 6:31:53 am

Hi all,

Is it possible to extend a kernel class in a custom extension ? For exemple ezOrder ?

I tried to create such an extension by making a "class myOrder extend ezOrder {}". It works of course but i can't add my view to the ezShop module.

I tried to add my new view to viewList() array but its not taken into consideration.

It would be great if we could extend a core class inside a module and to be able to add new views to this module without having to write down a new module with custom class.

This is the same topic as being able to override kernel functions (without going through the "php_include_path" technique).

This would be a great help by allowing us to make small changes, or to correct wrong behavior in kernel functions without having to modify ezp sources or to wait futur releases.

EZP is Great

Piotrek Karaś

Wednesday 07 November 2007 11:09:02 am

Isn't eZ Publish 4 supposed to provide such functionality (to override kernel classes)? Can anyone elaborate on that subject?

(...)

Here we go:
<i>Kernel classes may be overridden by classes in extensions, due to the new autoload regime (making kernel modifications mostly unnecessary), however this flexibility should be exercised with caution.</i>
http://ez.no/developer/news/ez_publish_4_0

Time to try ;)

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

André R.

Wednesday 07 November 2007 12:47:27 pm

Yes it is currently possible to override core classes in eZ Publish 4 with the autoload system, but it's not a intentional feature so might change in the future.

Could you elaborate on what you need it for? (bugs / missing features...)

Overriding classes is of course not recommended in the long run since your override classes could break stuff in a future version and you need to closely watch any changes that are made to those classes each time you update/upgrade.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Piotrek Karaś

Wednesday 07 November 2007 1:43:12 pm

That's interesting, the way it was described during the partner meeting - I got an impression that it was a goal that was going to be achieved ;)

Yes, I do see the possible risks, even though I suspect that override system is always provides little bit of safety and flexibility more than direct modification of critical files. Since I don't know how it works exactly at this point, I cannot assess it and tell you whether I will find it useful in the future or not. Maybe once I've played with it a bit in the next days.

I'm mostly thinking of altering some of the system core functions and options. eZ Publish is quite well written and it's very tempting to make use of it ;) The other thing is that I still may not see all the direct and elegant solutions. One of such things: http://ez.no/developer/forum/general/poll_unique_vote_options_summary_and_questions

Thanks,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

H-Works Agency

Wednesday 15 June 2011 6:19:21 am

Hello,

Is it possible to add/override a new view to a kernel module ?

Three simple examples/questions :

- You take the built-in "shop" module and you want to add a "reservation" view to it, how would you proceed ?

- Still in that module the built-in "basket" view doesn't suit your needs, how to override it ?

For now to resolve those problems i have to create a whole new module which is long, boring and conceptually not very satisfying.

Thanx in advance.

EZP is Great

Gaetano Giunta

Wednesday 15 June 2011 7:07:58 am

To add a view to an existing module, you could create the view in a custom module then add a virtual-url rule to make your custom view belong in the original module. One drawback: you cannot declare in module.php for module B that a view depends on an access function defined in module A. To do so, you'll have to do explicit perm checking within the view code.

Using url rewrites, you can also "take control" of existing views. Another way to reach the same goal is to change settings in site.ini so that your extension's modules/views are scanned before the kernel ones (but be careful with that)

Principal Consultant International Business
Member of the Community Project Board