Skip to content

Commit

Permalink
feat(MenuExtension): add a condition to get the locale from form in c…
Browse files Browse the repository at this point in the history
…ase the form is from a richEditor
  • Loading branch information
Etienne Gutbub committed Oct 8, 2024
1 parent e221cbd commit 880068b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Twig/Extension/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 880068b

Please sign in to comment.