2. 1. Why we needed a wrapper
2. What is ezobjectwrapper ?
3. Hands on exercises
4. Q&A
2
EzobjectWrapper
Workshop
3. Why we needed a
wrapper
01
● Performance issues when
displaying multiple contents in
the same page with ez_content:
viewLocation
● Rendering rules in classes rather
than repositories/controller
● Listing different content types
with the same HTML code
3
4. What is
EzobjectWrapper ?
02
● Bundle originally made by
Antonin Savoie, dev@Kaliop
● A wrapper encapsulates content
& location (lazy loading)
● Each wrapper provides its own
methods / business logic
● Factory creates corresponding
wrapper object depending on
content type
● Bonus : renderLocation twig
function
4
5. Github repos
Titre de la présentation à personnaliser 5
https://github.com/kaliop/ezobjectwrapper
https://github.com/kaliop/ezobjectwrapper-workshop
6. Encapsulates content & location
Titre de la présentation à personnaliser 6
public function __construct(ContainerInterface $container, $location = null, $content = null)
{
….
$this->location = $location;
$this->content = $content;
}
7. Lazy loading
Titre de la présentation à personnaliser 7
public function content()
{
if($this->content == null){
$this->content = $this->repository->getContentService()->loadContent($this->location->contentId);
}
return $this->content;
}
9. renderLocation Twig function
Titre de la présentation à personnaliser 9
{{ render( controller( "ez_content:viewLocation", {"locationId": 123, "viewType": "line"} ) ) }}
Before :
{{ renderLocation( 123, "line" )|raw }}
After :
public function renderLocation($locationID, $viewType, $params = array()) {
$rendering = $this->container->get('ezpublish.controller.content.view')->viewLocation($locationID, $viewType, false, $params);
return htmlspecialchars_decode($rendering->getContent());
}
How it works :
11. Check your ezobjwrapper instance is working
Titre de la présentation à personnaliser 11
$ cd /var/www/summercamp/workshops/ezobjwrapper
$ git pull
$ git checkout step-0
Open http://ezobjwrapper.ezsc in your browser