Skip to content

Commit

Permalink
feat: Removed NodeTypeFieldObjectConstructor.php for app:install to a…
Browse files Browse the repository at this point in the history
…void conflicts between object construction and dropping all fields. `node_type_name` JSON property is no-longer required
  • Loading branch information
roadiz-ci committed Mar 18, 2024
1 parent b7bf6ed commit 29954f4
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 101 deletions.
1 change: 0 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ services:
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\TagObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\NodeObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\NodeTypeObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\NodeTypeFieldObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\RoleObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\GroupObjectConstructor',
'@RZ\Roadiz\CoreBundle\Serializer\ObjectConstructor\SettingObjectConstructor',
Expand Down
3 changes: 0 additions & 3 deletions src/Entity/NodeTypeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ class NodeTypeField extends AbstractField implements NodeTypeFieldInterface, Ser
private bool $visible = true;

#[
Serializer\VirtualProperty(),
Serializer\Type("string"),
Serializer\Groups(["node_type"]),
SymfonySerializer\Groups(["node_type"])
]
public function getNodeTypeName(): string
Expand Down

This file was deleted.

33 changes: 0 additions & 33 deletions src/Serializer/ObjectConstructor/NodeTypeObjectConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use JMS\Serializer\DeserializationContext;
use JMS\Serializer\Exception\ObjectConstructionException;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Visitor\DeserializationVisitorInterface;
use RZ\Roadiz\CoreBundle\Entity\NodeType;

class NodeTypeObjectConstructor extends AbstractTypedObjectConstructor
Expand All @@ -20,37 +18,6 @@ public function supports(string $className, array $data): bool
return $className === NodeType::class && array_key_exists('name', $data);
}

public function construct(
DeserializationVisitorInterface $visitor,
ClassMetadata $metadata,
$data,
array $type,
DeserializationContext $context
): ?object {
$nodeType = parent::construct($visitor, $metadata, $data, $type, $context);

if ($nodeType instanceof NodeType && \is_array($data) && \array_key_exists('fields', $data)) {
$nodeType = $this->removeExtraFields($nodeType, $data);
}

return $nodeType;
}

protected function removeExtraFields(NodeType $nodeType, array $data): NodeType
{
$fieldsName = array_map(function ($field) {
return $field['name'];
}, $data['fields']);

foreach ($nodeType->getFields() as $field) {
if (!\in_array($field->getName(), $fieldsName)) {
$nodeType->getFields()->removeElement($field);
}
}

return $nodeType;
}

/**
* @inheritDoc
*/
Expand Down

0 comments on commit 29954f4

Please sign in to comment.