Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
This bundle give the possibility to visualize your contents data as a DTO (data transform object). A DTO (Data Transform Object) is a simple object with properties and getters/setters who store data. Ibexa Content object are complex and have a lot of information. A content object transformed into a DTO will be easier to read and use because it will contain only fields value (in current language for multiple languages).
- PHP 8.1 or later
- Ibexa 4.0 (Ibexa DXP) / Symfony 5.*
$ composer require HamHamFonFon/ibexa-content-dto
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
HamHamFonFon\IbexaContentDto\IbexaContentDtoBundle::class => ['all' => true],
];
Configure directory_repository
, directory_dto
and content_type_groups
values :
- directory_repository: path where repositories will be created (e.g.: src/Repository/)
- directory_dto: path where DTO will be created (e.g.: src/Entity/DTO/)
- content_type_groups: list of content-groups ("Content" by default)
# config/packages/ibx_content_dto.yaml
ibx_content_dto:
directory_repository: src/Path/To/Repository/Directory
directory_dto: src/Path/To/Dto/Directory
content_type_groups:
- Content
- Custom group...
DTO works in couple with a repository linked to it. DTO contains only fields values and repository retrieve data from your back-office helped with Ibexa repositories service.
There is two ways to create a couple DTO/repository
Create your DTO class, add properties (camelcase-style). Properties name must be same as fields identifier but in camel-case style.
Your DTO needs to extend AbstractDto
class and implements DtoInterface
interface. Add getters/setters and mandatory methods.
Example, you have a content-type article
with fields title
(ezstring), title_long
(ezstring), image_header
(ezimage), text
(ezrichtext), related_articles
(ezobjectrelationlist)
Your DTO will be like this :
use HamHamFonFon\IbexaContentDto\Entity\DtoInterface;
use HamHamFonFon\IbexaContentDto\Entity\Dto\AbstractDto;
class Article extends AbstractDto implements DtoInterface
{
protected ?string $title;
protected ?string $titleLong;
protected $image;
protected ?DOMDocument $text;
protected ListDto $relatedArticles;
// List of getters and setters...
/**
* @return array|null
*/
public function listObjectRelationListFields(): ?array
{
return ['relatedArticles'];
}
}
You can add your own methods in the DTO if you have specific needs.
Just use symfony command php bin/console dto:create
, both classes will be generated.
- Create or update content from a DTO
I accept contributions, please fork the project and submit pull requests.
In case you find some bugs or have question about this repository, open an issue and I will answer you as soon as possible.
Stéphane MEAUDRE [email protected]