Exemplo n.º 1
0
 /**
  * @covers \Magento\Framework\Stdlib\ArrayUtils::ksortMultibyte
  * @dataProvider ksortMultibyteDataProvider
  */
 public function testKsortMultibyte($input, $locale)
 {
     $this->_arrayUtils->ksortMultibyte($input, $locale);
     $iterator = 0;
     foreach ($input as $value) {
         $iterator++;
         $this->assertEquals($iterator, $value);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
     $options = [];
     foreach ($sort as $label => $value) {
         $option = ['value' => $value, 'label' => $label];
         if ($this->helperData->isRegionRequired($value)) {
             $option['is_region_required'] = true;
         }
         $options[] = $option;
     }
     if (count($options) > 0 && $emptyLabel !== false) {
         array_unshift($options, ['value' => '', 'label' => $emptyLabel]);
     }
     return $options;
 }
Exemplo n.º 3
0
 /**
  * Convert collection items to select options array
  *
  * @param string|boolean $emptyLabel
  * @return array
  */
 public function toOptionArray($emptyLabel = ' ')
 {
     $options = $this->_toOptionArray('country_id', 'name', array('title' => 'iso2_code'));
     $sort = array();
     foreach ($options as $data) {
         $name = (string) $this->_localeLists->getCountryTranslation($data['value']);
         if (!empty($name)) {
             $sort[$name] = $data['value'];
         }
     }
     $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocaleCode());
     foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) {
         $name = array_search($foregroundCountry, $sort);
         unset($sort[$name]);
         $sort = array($name => $foregroundCountry) + $sort;
     }
     $options = array();
     foreach ($sort as $label => $value) {
         $options[] = array('value' => $value, 'label' => $label);
     }
     if (count($options) > 0 && $emptyLabel !== false) {
         array_unshift($options, array('value' => '', 'label' => $emptyLabel));
     }
     return $options;
 }