/** * {@inheritdoc} * * Translate the locale codes to labels in the current user locale * and sort them alphabetically * * This part is done here because of the choices query is executed just before * so we can't access to these properties from form events */ public function finishView(FormView $view, FormInterface $form, array $options) { if (!isset($view['locales'])) { return; } /** @var array<ChoiceView> $locales */ $locales = $view['locales']; foreach ($locales->vars['choices'] as $locale) { $locale->label = $this->localeHelper->getLocaleLabel($locale->label); } foreach ($locales->vars['preferred_choices'] as $locale) { $locale->label = $this->localeHelper->getLocaleLabel($locale->label); } $locales->vars['choices'] = SortHelper::sortByProperty($locales->vars['choices'], 'label'); $locales->vars['preferred_choices'] = SortHelper::sortByProperty($locales->vars['preferred_choices'], 'label'); }
/** * Test related method * * @param array $values * @param array $expectedValues * * @dataProvider dataProviderSort */ public function testSort($values, $expectedValues) { $sortedValues = SortHelper::sort($values); $this->assertEquals($expectedValues, $sortedValues); }