localeLists = $localeLists; $this->state = $state; $this->availableLocales = $availableLocales; $this->design = $design; $this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class); } /** * {@inheritdoc} */ public function getOptionLocales(): array { return $this->filterLocales($this->localeLists->getOptionLocales()); } /** * {@inheritdoc} */ public function getTranslatedOptionLocales(): array { return $this->filterLocales($this->localeLists->getTranslatedOptionLocales()); } /** * Filter list of locales by available locales for current theme and depends on running application mode. * * Applies filters only in production mode when flag 'static_content_on_demand_in_production' is not enabled. * For example, if the current design theme has only one generated locale en_GB then for given array of locales: * ```php * $locales = [ * 0 => [ * 'value' => 'da_DK' * 'label' => 'Danish (Denmark)' * ], * 1 => [ * 'value' => 'de_DE' * 'label' => 'German (Germany)' * ], * 2 => [ * 'value' => 'en_GB' * 'label' => 'English (United Kingdom)' * ], * ] * ``` * result will be: * ```php * [ * 2 => [ * 'value' => 'en_GB' * 'label' => 'English (United Kingdom)' * ], * ] * ``` * * @param array $locales list of locales for filtering * @return array of filtered locales */ private function filterLocales(array $locales): array { if ($this->state->getMode() != State::MODE_PRODUCTION || $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { return $locales; } $theme = $this->design->getDesignTheme(); try { $availableLocales = $this->availableLocales->getList($theme->getCode(), $theme->getArea()); } catch (LocalizedException $e) { $availableLocales = []; } return array_filter($locales, function ($localeData) use ($availableLocales) { return in_array($localeData['value'], $availableLocales); }); } }