/** * Convert collection items to select options array * * @param string|boolean $emptyLabel * @return array */ public function toOptionArray($emptyLabel = ' ') { $options = $this->_toOptionArray('country_id', 'name', ['title' => 'iso2_code']); $sort = []; foreach ($options as $data) { $name = (string) $this->_localeLists->getCountryTranslation($data['value']); if (!empty($name)) { $sort[$name] = $data['value']; } } $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale()); foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) { $name = array_search($foregroundCountry, $sort); unset($sort[$name]); $sort = [$name => $foregroundCountry] + $sort; } $isRegionVisible = (bool) $this->helperData->isShowNonRequiredState(); $options = []; foreach ($sort as $label => $value) { $option = ['value' => $value, 'label' => $label]; if ($this->helperData->isRegionRequired($value)) { $option['is_region_required'] = true; } else { $option['is_region_visible'] = $isRegionVisible; } if ($this->helperData->isZipCodeOptional($value)) { $option['is_zipcode_optional'] = true; } $options[] = $option; } if (count($options) > 0 && $emptyLabel !== false) { array_unshift($options, ['value' => '', 'label' => $emptyLabel]); } return $options; }
/** * Return, whether non-required state should be shown * * @return int 1 if should be shown, and 0 if not. */ public function getShowAllRegions() { return (string) $this->_directoryHelper->isShowNonRequiredState() ? 1 : 0; }