/** * Build a choice list object. * * @return SimpleChoiceList */ public function getChoiceList(array $restrict = array()) { $locales = $this->localeRepository->findAll(); if (!empty($restrict)) { $locales = array_filter($locales, function ($locale) use($restrict) { return in_array((string) $locale, $restrict); }); } // Sort locales by display names usort($locales, function ($locale1, $locale2) { $displayLocale1 = (string) DisplayLocale::createFromLocale($locale1); $displayLocale2 = (string) DisplayLocale::createFromLocale($locale2); return strcmp($displayLocale1, $displayLocale2); }); $keys = array_map(function ($locale) { return (string) $locale; }, $locales); $values = array_map(function ($locale) { return (string) DisplayLocale::createFromLocale($locale); }, $locales); return new SimpleChoiceList(array_combine($keys, $values)); }
public function __construct(Locale $locale) { $displayLocale = DisplayLocale::createFromLocale($locale); $this->locale = (string) $locale; $this->name = $displayLocale->getName(); }