Skip to content

Commit

Permalink
Merge branch hotfix/v2.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Feb 23, 2024
1 parent 7fdbe38 commit 0909e86
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
50 changes: 37 additions & 13 deletions src/Form/Constraint/NodeTypeFieldValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
6 changes: 6 additions & 0 deletions translations/validators.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<source>tagName.%name%.alreadyExists</source>
<target state="translated">Tag %name% already exists.</target>
</trans-unit>


<trans-unit id="field_with_same_name_already_exists_but_with_different_doctrine_type" xml:space="preserve">
<source>field_with_same_name_already_exists_but_with_different_doctrine_type</source>
<target state="translated">There already is a "%name%" field inside "%nodeTypeName%" but with a different data-type: %type%.</target>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions translations/validators.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<source>tagName.%name%.alreadyExists</source>
<target state="translated">L'étiquette «%name%» existe déjà.</target>
</trans-unit>

<trans-unit id="field_with_same_name_already_exists_but_with_different_doctrine_type" xml:space="preserve">
<source>field_with_same_name_already_exists_but_with_different_doctrine_type</source>
<target state="translated">Un champ « %name% » existe déjà pour « %nodeTypeName% » mais avec un type de données différent : %type%.</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions translations/validators.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<source>tagName.%name%.alreadyExists</source>
<target />
</trans-unit>
<trans-unit id="field_with_same_name_already_exists_but_with_different_doctrine_type" xml:space="preserve">
<source>field_with_same_name_already_exists_but_with_different_doctrine_type</source>
<target />
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 0909e86

Please sign in to comment.