Solution: Overriding kernel classes within an extension

This feature is available since eZ publish 4.1.

About

The best way to override kernel classes within eZ Publish.

This article features solutions for both eZ Pubish 3 and eZ Publish 4.

Please notice that the primary solution described for eZ Publish 4 is a supported but not recommended feature.

Please use with care and caution when working with the internals of the eZ Publish Kernel.

Question

What is the best way to override default eZ Publish kernel classes?

Answers

Several solutions come to mind. The best solution in eZ Publish 4 is to override the class within an extension. Remember this should be considered kernel hacking which while allowed and even more supported than ever in eZ Publish 4 it is still causioned.

PATCHING

In the past the best way to do this was to simply patch the original file and replace it with a modified file within original kernel location.

Creating a Kernel Override Extension

This is the standard solution within eZ Publish.

Create and activate extension

See articles on creating an extension

Copy default kernel file into the extension.

Remember pathing is a relative scheme (pattern) which must be maintained within the extension directory root.

mkdir -p extension/customname/kernel/classes/; cp -va kernel/classes/ezcontentobjecttree.php extension/customname/kernel/classes/; 

Configure config.php enable kernel overrides

Create if file does not exist in root of ezpublish directory. Edit config.php file and enable the following setting.

EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE

Activating kernel override extension

  • Activate extension in settings
  • Regenerate autoload cache
./bin/php/ezpgenerateautoload.php -o 

References