config = $config; $this->locationsList = $locationsList; } /** * @return array */ public function toOptionArray(): array { $regions = $this->locationsList->getRegions(); $countries = $this->locationsList->getCountries(); if (! $this->config->isConfiguredForUse()) { $regions = array_map([$this, 'addDisabledAttribute'], $regions); $countries = array_map([$this, 'addDisabledAttribute'], $countries); } return [ [ 'label' => __('By Region'), 'value' => $regions, ], [ 'label' => __('By Country'), 'value' => $countries, ], ]; } /** * @param array $option * @return mixed */ public function addDisabledAttribute($option) { if (LocationsList::ALL !== $option['value']) { $option['params']['disabled'] = 'disabled'; } return $option; } }