From 0909e861d6df40a7d9468941ca1f56e672d7e31c Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Fri, 23 Feb 2024 12:25:34 +0000 Subject: [PATCH] Merge branch hotfix/v2.2.5 --- config/services.yaml | 2 +- .../Constraint/NodeTypeFieldValidator.php | 50 ++++++++++++++----- translations/validators.en.xlf | 6 +++ translations/validators.fr.xlf | 5 ++ translations/validators.xlf | 4 ++ 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 623c89ee..d39839c1 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,6 +1,6 @@ --- parameters: - roadiz_core.cms_version: '2.2.4' + roadiz_core.cms_version: '2.2.5' roadiz_core.cms_version_prefix: 'main' env(APP_NAMESPACE): "roadiz" env(APP_VERSION): "0.1.0" diff --git a/src/Form/Constraint/NodeTypeFieldValidator.php b/src/Form/Constraint/NodeTypeFieldValidator.php index 9ba3b5c0..696252df 100644 --- a/src/Form/Constraint/NodeTypeFieldValidator.php +++ b/src/Form/Constraint/NodeTypeFieldValidator.php @@ -4,6 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Form\Constraint; +use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\Core\AbstractEntities\PersistableInterface; use RZ\Roadiz\CoreBundle\Configuration\CollectionFieldConfiguration; use RZ\Roadiz\CoreBundle\Configuration\JoinNodeTypeFieldConfiguration; @@ -19,23 +20,46 @@ class NodeTypeFieldValidator extends ConstraintValidator { + public function __construct( + private readonly ManagerRegistry $registry, + ) { + } + public function validate(mixed $value, Constraint $constraint): void { - if ($value instanceof NodeTypeFieldEntity) { - if ($value->isMarkdown()) { - $this->validateMarkdownOptions($value); - } - if ($value->isManyToMany() || $value->isManyToOne()) { - $this->validateJoinTypes($value, $constraint); - } - if ($value->isMultiProvider() || $value->isSingleProvider()) { - $this->validateProviderTypes($value, $constraint); + if (!$value instanceof NodeTypeFieldEntity) { + $this->context->buildViolation('Value is not a valid NodeTypeField.')->addViolation(); + return; + } + + $existingNodeTypeFieldsByName = $this->registry->getRepository(NodeTypeFieldEntity::class)->findBy([ + 'name' => $value->getName(), + ]); + foreach ($existingNodeTypeFieldsByName as $item) { + if ($item->getId() === $value->getId()) { + continue; } - if ($value->isCollection()) { - $this->validateCollectionTypes($value, $constraint); + if ($item->getDoctrineType() !== $value->getDoctrineType()) { + $this->context->buildViolation('field_with_same_name_already_exists_but_with_different_doctrine_type') + ->setParameter('%name%', $item->getName()) + ->setParameter('%nodeTypeName%', $item->getNodeTypeName()) + ->setParameter('%type%', $item->getDoctrineType()) + ->atPath('name') + ->addViolation(); } - } else { - $this->context->buildViolation('Value is not a valid NodeTypeField.')->addViolation(); + } + + if ($value->isMarkdown()) { + $this->validateMarkdownOptions($value); + } + if ($value->isManyToMany() || $value->isManyToOne()) { + $this->validateJoinTypes($value, $constraint); + } + if ($value->isMultiProvider() || $value->isSingleProvider()) { + $this->validateProviderTypes($value, $constraint); + } + if ($value->isCollection()) { + $this->validateCollectionTypes($value, $constraint); } } diff --git a/translations/validators.en.xlf b/translations/validators.en.xlf index 62c27ea0..c10b9005 100644 --- a/translations/validators.en.xlf +++ b/translations/validators.en.xlf @@ -10,6 +10,12 @@ tagName.%name%.alreadyExists Tag %name% already exists. + + + + field_with_same_name_already_exists_but_with_different_doctrine_type + There already is a "%name%" field inside "%nodeTypeName%" but with a different data-type: %type%. + diff --git a/translations/validators.fr.xlf b/translations/validators.fr.xlf index 0daaf454..9e538c0e 100644 --- a/translations/validators.fr.xlf +++ b/translations/validators.fr.xlf @@ -10,6 +10,11 @@ tagName.%name%.alreadyExists L'étiquette «%name%» existe déjà. + + + field_with_same_name_already_exists_but_with_different_doctrine_type + Un champ « %name% » existe déjà pour « %nodeTypeName% » mais avec un type de données différent : %type%. + diff --git a/translations/validators.xlf b/translations/validators.xlf index 82fbfc32..413ebfd4 100644 --- a/translations/validators.xlf +++ b/translations/validators.xlf @@ -10,6 +10,10 @@ tagName.%name%.alreadyExists + + field_with_same_name_already_exists_but_with_different_doctrine_type + +