Skip to content

Commit

Permalink
feat: Serialize tag parent in DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Feb 14, 2022
1 parent a5a9b9d commit c48fb11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ doctrine:
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
dql:
string_functions:
JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
Expand Down
3 changes: 3 additions & 0 deletions src/Api/DataTransformer/TagOutputDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function transform($data, string $to, array $context = []): object
$output->slug = $data->getTagName();
$output->color = $data->getColor();
$output->visible = $data->isVisible();
if ($data->getParent() instanceof Tag) {
$output->parent = $data->getParent();
}

if (isset($context['translation']) && $context['translation'] instanceof TranslationInterface) {
$translatedData = $data->getTranslatedTagsByTranslation($context['translation'])->first() ?: null;
Expand Down
8 changes: 8 additions & 0 deletions src/Api/Dto/TagOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace RZ\Roadiz\CoreBundle\Api\Dto;

use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;

final class TagOutput
{
Expand Down Expand Up @@ -39,4 +41,10 @@ final class TagOutput
* @Groups({"tag", "tag_base"})
*/
public array $documents = [];
/**
* @var Tag|null
* @Groups({"tag", "tag_base"})
* @MaxDepth(1)
*/
public ?Tag $parent = null;
}
4 changes: 3 additions & 1 deletion src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ class Tag extends AbstractDateTimedPositioned implements LeafInterface
* "nodes.id": "exact",
* "nodes.nodeName": "exact",
* "nodes.parent": "exact",
* "nodes.parent.nodeName": "exact",
* "nodes.tags": "exact",
* "nodes.tags.tagName": "exact",
* "nodes.nodeType": "exact",
* "nodes.nodeType.name": "exact"
* "nodes.nodeType.name": "exact",
* "nodes.parent.nodeType.name": "exact"
* })
*/
private Collection $nodes;
Expand Down

0 comments on commit c48fb11

Please sign in to comment.