eZ Community » Forums » eZ Publish 5 Platform » Module/Page not found error

Module/Page not found error

Module/Page not found error

Wednesday 13 March 2013 2:51:21 pm - 4 replies

Is there a way to "intercept" the Module/Page Not Found error in order to process it via pure twig/symfony instead of the fallback into legacy mode?

Thursday 14 March 2013 3:33:48 pm

Hi Michael, 

The short answer appears to be that no, the legacy kernel still handles all error messages. 

By default, eZ routes all requests not handled elsewhere to eZ\Bundle\EzPublishLegacyBundle\Controller\LegacyKernelController\indexAction, the assumption being that if a URL isn't handled by the symfony stack, it might be handled by the legacy stack. 

This action fires up the legacy kernel, passes it the request, and wraps the output in a response object.

A couple of thoughts on this:

  • You could probably avoid this by adjusting the routing to stop routing everything to legacy, and only routing pieces you explicitly know you'll need. This would likely need to be done in a way that doesn't affect the admin.
  • This would be easier to handle if ezpKernelResult would pass along the $moduleResult array instead of the just taking the rendered content. This would be a simple change, and it would allow the symfony-stack developers to do more parsing on the requests. 

Friday 15 March 2013 2:53:36 pm

Hi Joe,

Do you have any examples on how I would modify the code to achieve the behavior in you second bullet?

I am working on building a site in the pure Symfony stack.

Friday 15 March 2013 11:10:40 pm


I played with this a bit since I have the same issue on my sites, and I've solved it in a way. But... I've done some things I'm not proud of

The problem here is that the when the Symfony stack doesn't know what to do with the request, it hands it off the the legacy stack hoping that legacy will have it. LegacyKernelController runs the legacy stack and returns the result, but the only thing that the legacy kernel returns is a fully-completed legacy request, with no additional information. So unless you've done your templates again in the legacy kernel, you have an ugly response. 

There are only two ways I see around this: either make the EzPublishLegacyBundle FallbackRouter smarter so it only routes requests to legacy that will be truly handled, or to make the legacy kernel return more information to LegacyKernelController so you can choose to monkey with the response. I took the latter approach since it seemed easier, even though it required a core hack

First, the last line of kernel/private/classes/ezpkernelweb::run() is this: 

return new ezpKernelResult( $content ); 

I changed it to this: 

$kernelResult = new ezpKernelResult( $content );
$kernelResult->setAttribute('module_result', $moduleResult);
return $kernelResult; 

So now, in addition to content, ezpKernelResult now also returns the moduleResult array. 

Then, I overrode the LegacyKernelController with my own controller using a custom bundle. You can find the code here: 


Basically I sniffed for the ui_component in $moduleResult and chose to display my own template instead of the default one. 

A better way to handle this would be to just route everything to a template and have the twig template output $module_result.content. That way your Twig template could handle all of the legacy output. 

This feels like an area that could use a lot of improvement yet. With a few simple changes to ezpkernelweb and LegacyKernelController, you could probably have the option of avoiding the creation of a pagelayout.tpl in most circumstances.





Saturday 16 March 2013 7:01:47 pm

I've submitted code to make this an official option: 




You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from