diff --git a/src/Twig/Extension/MenuExtension.php b/src/Twig/Extension/MenuExtension.php index ebd2f59..df9e39a 100644 --- a/src/Twig/Extension/MenuExtension.php +++ b/src/Twig/Extension/MenuExtension.php @@ -70,6 +70,9 @@ public function getMenuFirstLevelItems(string $menuCode): ?array return $this->menus[$menuCode]->getFirstLevelItems(); } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ public function getLocaleFromForm(FormView $form): ?string { $currentForm = $form; @@ -81,8 +84,9 @@ public function getLocaleFromForm(FormView $form): ?string $parentForm = $currentForm->parent; $blockPrefixes = $parentForm?->vars['block_prefixes'] ?? []; if ( - \in_array(self::SYLIUS_TRANSLATION_BLOCK_PREFIX, $blockPrefixes, true) // Check the parent is `sylius_translations` - && null !== ($locale = $currentForm->vars['name'] ?? null) // Check the current form has a name (containing the locale code) + (\in_array(self::SYLIUS_TRANSLATION_BLOCK_PREFIX, $blockPrefixes, true) // Check the parent is `sylius_translations` + && null !== ($locale = $currentForm->vars['name'] ?? null)) // Check the current form has a name (containing the locale code) + || (null !== ($locale = $currentForm->vars['attr']['data-locale'] ?? null)) // Check if the form has a data-locale attribute in case of rich-editor ) { return $locale; }