12
It’s all about eXperience EzobjectWrapper Workshop

Ezobject wrapper workshop

Embed Size (px)

Citation preview

Page 1: Ezobject wrapper workshop

It’s all about eXperience

EzobjectWrapper Workshop

Page 2: Ezobject wrapper workshop

1. Why we needed a wrapper

2. What is ezobjectwrapper ?

3. Hands on exercises

4. Q&A2

EzobjectWrapper Workshop

Page 3: Ezobject wrapper workshop

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

Page 4: Ezobject wrapper workshop

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

Page 5: Ezobject wrapper workshop

Github repos

Titre de la présentation à personnaliser 5

https://github.com/kaliop/ezobjectwrapper

https://github.com/kaliop/ezobjectwrapper-workshop

Page 6: Ezobject wrapper workshop

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; }

Page 7: Ezobject wrapper workshop

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; }

Page 8: Ezobject wrapper workshop

EzobjectWrapper factory

Titre de la présentation à personnaliser 8

public function buildeZObjectWrapper($source) { $locationSource = null; $contentSource = null;

if(is_numeric($source)) { $locationSource = $source = $this->repository->getLocationService()->loadLocation($source); } elseif($source instanceof Content) { $contentSource = $source; } else { $locationSource = $source; }

$contentTypeIdentifier = $this->repository->getContentTypeService()->loadContentType($source->contentInfo->contentTypeId)->identifier; $mappingEntities = $this->container->getParameter('class_mapping'); $defaultClass = $this->container->getParameter('default_ezobject_class');

if(isset($mappingEntities[$contentTypeIdentifier])){ $className = $mappingEntities[$contentTypeIdentifier]; } else { $className = $defaultClass; }

$objectWrapper = new $className($this->container, $locationSource, $contentSource);

return $objectWrapper; }

Page 9: Ezobject wrapper workshop

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 :

Page 10: Ezobject wrapper workshop

Hands on exercises

0310

Page 11: Ezobject wrapper workshop

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

Page 12: Ezobject wrapper workshop

Q&A

0412