Skip to content

Commit

Permalink
Merge pull request #42 from etienne-monsieurbiz/feature/url-type-impr…
Browse files Browse the repository at this point in the history
…ovements
  • Loading branch information
maximehuran authored Oct 8, 2024
2 parents e221cbd + 880068b commit 4e5d44a
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 4e5d44a

Please sign in to comment.