Skip to content

Commit

Permalink
feat: Added new NodeTypeField.php normalizationContext to alter nor…
Browse files Browse the repository at this point in the history
…malization groups per field basis (#29)
  • Loading branch information
roadiz-ci committed Dec 19, 2024
1 parent e85489e commit b45b346
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"require-dev": {
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan": "^1.5.3",
"phpstan/phpdoc-parser": "<2",
"phpstan/phpstan-doctrine": "^1.3",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.4.*",
Expand Down
29 changes: 29 additions & 0 deletions migrations/Version20241218095458.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241218095458 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added normalization_context to NodeTypeField';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE node_type_fields ADD normalization_context JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE node_type_fields DROP normalization_context');
}
}
37 changes: 37 additions & 0 deletions src/Entity/NodeTypeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class NodeTypeField extends AbstractField implements NodeTypeFieldInterface, Ser
]
private ?array $serializationGroups = null;

#[
Serializer\Groups(['node_type']),
SymfonySerializer\Groups(['node_type']),
Serializer\Type('array<string, array>'),
ORM\Column(name: 'normalization_context', type: 'json', nullable: true)
]
private ?array $normalizationContext = null;

#[
Serializer\Groups(['node_type']),
SymfonySerializer\Groups(['node_type']),
Expand Down Expand Up @@ -330,4 +338,33 @@ public function setExcludedFromSerialization(bool $excludedFromSerialization): N

return $this;
}

public function getNormalizationContext(): ?array
{
return $this->normalizationContext;
}

public function setNormalizationContext(?array $normalizationContext): NodeTypeField
{
$this->normalizationContext = $normalizationContext;

return $this;
}

#[SymfonySerializer\Ignore]
public function getNormalizationContextGroups(): ?array
{
return $this->normalizationContext['groups'] ?? [];
}

#[SymfonySerializer\Ignore]
public function setNormalizationContextGroups(?array $normalizationContextGroups): NodeTypeField
{
if (null === $normalizationContextGroups) {
$this->normalizationContext = null;
}
$this->normalizationContext['groups'] = $normalizationContextGroups;

return $this;
}
}

0 comments on commit b45b346

Please sign in to comment.