It’s all about eXperience
EzobjectWrapper
Workshop
1. Why we needed a wrapper
2. What is ezobjectwrapper ?
3. Hands on exercises
4. Q&A
2
EzobjectWrapper
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
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
Github repos
Titre de la présentation à personnaliser 5
https://github.com/kaliop/ezobjectwrapper
https://github.com/kaliop/ezobjectwrapper-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;
}
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;
}
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;
}
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 :
Hands on exercises
03 10
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
Q&A
04 12

Ezobject wrapper workshop

  • 1.
    It’s all abouteXperience EzobjectWrapper Workshop
  • 2.
    1. Why weneeded a wrapper 2. What is ezobjectwrapper ? 3. Hands on exercises 4. Q&A 2 EzobjectWrapper Workshop
  • 3.
    Why we neededa 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 dela 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 dela présentation à personnaliser 7 public function content() { if($this->content == null){ $this->content = $this->repository->getContentService()->loadContent($this->location->contentId); } return $this->content; }
  • 8.
    EzobjectWrapper factory Titre dela 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; }
  • 9.
    renderLocation Twig function Titrede 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 :
  • 10.
  • 11.
    Check your ezobjwrapperinstance 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
  • 12.