ezsystems/ezpublish-kernel
eZ Publish Kernel is the core of the eZ Publish/eZ Platform CMS, providing the content repository, field types, search integration, and services for building and extending PHP-based content applications with a modular, API-driven architecture.
In some cases, displaying a content/location via the built-in ViewController is not sufficient and will lead you to do many sub-requests in order to access different parameters.
Typical use cases are access to:
In those cases, you may want to use your own controller to display the current
content/location instead of using the built-in ViewController.
This feature covers 2 general use cases:
This is possible with the following piece of configuration:
ezpublish:
system:
my_siteaccess:
location_view:
full:
custom_controller_test:
# The following will let you use your own custom controller for location #123
# (Here it will use AcmeTestBundle/Controller/DefaultController::viewLocationAction(),
# following the Symfony controller notation convention.
# Method viewLocationAction() must follow the same prototype as in the built-in ViewController
controller: AcmeTestBundle:Default:viewLocation
match:
Id\Location: 123
The only requirement here is that your action method has the same signature than ViewController::viewLocation() or ViewController::viewContent() (depending on what you're matching of course).
viewLocation() signature:
<?php
/**
* Main action for viewing content through a location in the repository.
*
* [@param](https://github.com/param) int $locationId
* [@param](https://github.com/param) string $viewType
* [@param](https://github.com/param) boolean $layout
* [@param](https://github.com/param) array $params
*
* [@throws](https://github.com/throws) \Symfony\Component\Security\Core\Exception\AccessDeniedException
* [@throws](https://github.com/throws) \Exception
*
* [@return](https://github.com/return) \Symfony\Component\HttpFoundation\Response
*/
public function viewLocation( $locationId, $viewType, $layout = false, array $params = array() )
viewContent() signature:
<?php
/**
* Main action for viewing content.
*
* [@param](https://github.com/param) int $contentId
* [@param](https://github.com/param) string $viewType
* [@param](https://github.com/param) boolean $layout
* [@param](https://github.com/param) array $params
*
* [@throws](https://github.com/throws) \Symfony\Component\Security\Core\Exception\AccessDeniedException
* [@throws](https://github.com/throws) \Exception
*
* [@return](https://github.com/return) \Symfony\Component\HttpFoundation\Response
*/
public function viewContent( $contentId, $viewType, $layout = false, array $params = array() )
Note:
Controller selection doesn't apply to
block_viewsince you can already use your own controller to display blocks.
Using your own controller, it is your responsibility to define cache rules, like for every custom controller !
So don't forget to set cache rules and the appropriate X-Location-Id header in the returned Response object.
See built-in ViewController for more details on this.
One other way to keep control on what is passed to the view is to use your own controller instead of the built-in ViewController.
Base ViewController being defined as a service, with a service alias, this can be easily achieved from your bundle's configuration:
parameters:
my.custom.view_controller.class: Acme\TestBundle\MyViewController
services:
my.custom.view_controller:
class: %my.custom.view_controller.class%
arguments: [[@some_dependency](https://github.com/some_dependency), [@other_dependency](https://github.com/other_dependency)]
# Change the alias here and make it point to your own controller
ez_content:
alias: my.custom.view_controller
Warning ! Doing so will completely override the built-in ViewController! Use this at your own risk!
How can I help you explore Laravel packages today?