Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Country.php
Go to the documentation of this file.
1 <?php
7 
15 {
22 
28  protected $_options;
29 
33  public function __construct(\Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection)
34  {
35  $this->_countryCollection = $countryCollection;
36  }
37 
45  public function toOptionArray($isMultiselect = false, $foregroundCountries = '')
46  {
47  if (!$this->_options) {
48  $this->_options = $this->_countryCollection->loadData()->setForegroundCountries(
49  $foregroundCountries
50  )->toOptionArray(
51  false
52  );
53  }
54 
56  if (!$isMultiselect) {
57  array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
58  }
59 
60  return $options;
61  }
62 }
__construct(\Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection)
Definition: Country.php:33
__()
Definition: __.php:13
toOptionArray($isMultiselect=false, $foregroundCountries='')
Definition: Country.php:45