Ezobject wrapper workshop
-
Upload
kaliop-slide -
Category
Technology
-
view
1.352 -
download
0
Transcript of Ezobject wrapper workshop
![Page 1: Ezobject wrapper workshop](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/1.jpg)
It’s all about eXperience
EzobjectWrapper Workshop
![Page 2: Ezobject wrapper workshop](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/2.jpg)
1. Why we needed a wrapper
2. What is ezobjectwrapper ?
3. Hands on exercises
4. Q&A2
EzobjectWrapper Workshop
![Page 3: Ezobject wrapper workshop](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/10.jpg)
Hands on exercises
0310
![Page 11: Ezobject wrapper workshop](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022050614/5a6cf9d17f8b9aec418b4841/html5/thumbnails/12.jpg)
Q&A
0412