diff --git a/CHANGELOG.md b/CHANGELOG.md index 9379b318..d60c6fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to Roadiz will be documented in this file. +## [2.3.11](https://github.com/roadiz/core-bundle-dev-app/compare/v2.3.10...v2.3.11) - 2024-06-17 + +### Bug Fixes + +- **(Attributes)** Fixed AttributeValueRepository findByAttributable method preventing fetch attribute values without translations. Fixed AttributeChoiceType still requesting entityManager. - ([1ce795e](https://github.com/roadiz/core-bundle-dev-app/commit/1ce795ec77ac85af9aeee2d8d43520b21d214791)) + ## [2.3.10](https://github.com/roadiz/core-bundle-dev-app/compare/v2.3.9...v2.3.10) - 2024-06-14 ### Bug Fixes diff --git a/lib/RoadizCoreBundle/config/services.yaml b/lib/RoadizCoreBundle/config/services.yaml index eb48f24e..3619b2d8 100644 --- a/lib/RoadizCoreBundle/config/services.yaml +++ b/lib/RoadizCoreBundle/config/services.yaml @@ -1,6 +1,6 @@ --- parameters: - roadiz_core.cms_version: '2.3.10' + roadiz_core.cms_version: '2.3.11' roadiz_core.cms_version_prefix: 'main' env(APP_NAMESPACE): "roadiz" env(APP_VERSION): "0.1.0" diff --git a/lib/RoadizCoreBundle/src/Form/AttributeChoiceType.php b/lib/RoadizCoreBundle/src/Form/AttributeChoiceType.php index 93c4554b..5c421243 100644 --- a/lib/RoadizCoreBundle/src/Form/AttributeChoiceType.php +++ b/lib/RoadizCoreBundle/src/Form/AttributeChoiceType.php @@ -4,7 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Form; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\CoreBundle\Entity\Attribute; use RZ\Roadiz\CoreBundle\Entity\Translation; use Symfony\Component\Form\AbstractType; @@ -14,8 +14,12 @@ use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -class AttributeChoiceType extends AbstractType +final class AttributeChoiceType extends AbstractType { + public function __construct(private ManagerRegistry $managerRegistry) + { + } + /** * @inheritDoc */ @@ -28,8 +32,8 @@ function ($dataToForm) { } return null; }, - function ($formToData) use ($options) { - return $options['entityManager']->find(Attribute::class, $formToData); + function ($formToData) { + return $this->managerRegistry->getRepository(Attribute::class)->find($formToData); } )); } @@ -41,14 +45,12 @@ public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); $resolver->setDefault('empty_data', null); - $resolver->setRequired('entityManager'); - $resolver->setAllowedTypes('entityManager', [EntityManagerInterface::class]); $resolver->setRequired('translation'); $resolver->setAllowedTypes('translation', [Translation::class]); $resolver->setNormalizer('choices', function (Options $options) { $choices = []; /** @var Attribute[] $attributes */ - $attributes = $options['entityManager']->getRepository(Attribute::class)->findBy( + $attributes = $this->managerRegistry->getRepository(Attribute::class)->findBy( [], ['code' => 'ASC'] ); diff --git a/lib/RoadizCoreBundle/src/Form/AttributeValueType.php b/lib/RoadizCoreBundle/src/Form/AttributeValueType.php index 93aa5d4c..452523da 100644 --- a/lib/RoadizCoreBundle/src/Form/AttributeValueType.php +++ b/lib/RoadizCoreBundle/src/Form/AttributeValueType.php @@ -19,7 +19,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('attribute', AttributeChoiceType::class, [ 'label' => 'attribute_values.form.attribute', - 'entityManager' => $options['entityManager'], 'translation' => $options['translation'], ]); } @@ -31,8 +30,6 @@ public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); - $resolver->setRequired('entityManager'); - $resolver->setAllowedTypes('entityManager', [EntityManagerInterface::class]); $resolver->setRequired('translation'); $resolver->setAllowedTypes('translation', [Translation::class]); } diff --git a/lib/RoadizCoreBundle/src/Repository/AttributeValueRepository.php b/lib/RoadizCoreBundle/src/Repository/AttributeValueRepository.php index d494a49c..c49f0774 100644 --- a/lib/RoadizCoreBundle/src/Repository/AttributeValueRepository.php +++ b/lib/RoadizCoreBundle/src/Repository/AttributeValueRepository.php @@ -38,7 +38,8 @@ public function findByAttributable( ->addSelect('ad') ->addSelect('ag') ->addSelect('agt') - ->innerJoin('av.attributeValueTranslations', 'avt') + // We need to fetch values without translations too + ->leftJoin('av.attributeValueTranslations', 'avt') ->innerJoin('av.attribute', 'a') ->leftJoin('a.attributeDocuments', 'ad') ->leftJoin('a.attributeTranslations', 'at') diff --git a/lib/Rozier/src/Controllers/Nodes/NodesAttributesController.php b/lib/Rozier/src/Controllers/Nodes/NodesAttributesController.php index 41462328..f1dfe96e 100644 --- a/lib/Rozier/src/Controllers/Nodes/NodesAttributesController.php +++ b/lib/Rozier/src/Controllers/Nodes/NodesAttributesController.php @@ -201,7 +201,6 @@ protected function handleAddAttributeForm(Request $request, Node $node, Translat $attributeValue = new AttributeValue(); $attributeValue->setAttributable($node); $addAttributeForm = $this->createForm(AttributeValueType::class, $attributeValue, [ - 'entityManager' => $this->em(), 'translation' => $this->em()->getRepository(Translation::class)->findDefault(), ]); $addAttributeForm->handleRequest($request); @@ -210,6 +209,18 @@ protected function handleAddAttributeForm(Request $request, Node $node, Translat $this->em()->persist($attributeValue); $this->em()->flush(); + $nodeSource = $node->getNodeSourcesByTranslation($translation)->first() ?: null; + if ($nodeSource instanceof NodesSources) { + $msg = $this->getTranslator()->trans( + 'attribute_value_translation.%name%.updated_from_node.%nodeName%', + [ + '%name%' => $attributeValue->getAttribute()->getLabelOrCode($translation), + '%nodeName%' => $nodeSource->getTitle(), + ] + ); + $this->publishConfirmMessage($request, $msg, $nodeSource); + } + return $this->redirectToRoute('nodesEditAttributesPage', [ 'nodeId' => $node->getId(), 'translationId' => $translation->getId(),