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 
10 
14 class Country implements ArrayInterface
15 {
19  protected $options;
20 
26  protected $countryCollection;
27 
31  protected $excludedCountries = [
32  'MM',
33  'IR',
34  'SD',
35  'BY',
36  'CI',
37  'CD',
38  'CG',
39  'IQ',
40  'LR',
41  'LB',
42  'KP',
43  'SL',
44  'SY',
45  'ZW',
46  'AL',
47  'BA',
48  'MK',
49  'ME',
50  'RS'
51  ];
52 
57  {
58  $this->countryCollection = $countryCollection;
59  }
60 
65  public function toOptionArray($isMultiselect = false)
66  {
67  if (!$this->options) {
68  $this->options = $this->countryCollection
69  ->addFieldToFilter('country_id', ['nin' => $this->getExcludedCountries()])
70  ->loadData()
71  ->toOptionArray(false);
72  }
73 
75  if (!$isMultiselect) {
76  array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
77  }
78 
79  return $options;
80  }
81 
88  public function isCountryRestricted($countryId)
89  {
90  return in_array($countryId, $this->getExcludedCountries());
91  }
92 
97  public function getExcludedCountries()
98  {
100  }
101 }
__()
Definition: __.php:13
__construct(Collection $countryCollection)
Definition: Country.php:56