1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Directory\Model\Config\Source;
- /**
- * Options provider for countries list
- *
- * @api
- * @since 100.0.2
- */
- class Country implements \Magento\Framework\Option\ArrayInterface
- {
- /**
- * Countries
- *
- * @var \Magento\Directory\Model\ResourceModel\Country\Collection
- */
- protected $_countryCollection;
- /**
- * Options array
- *
- * @var array
- */
- protected $_options;
- /**
- * @param \Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection
- */
- public function __construct(\Magento\Directory\Model\ResourceModel\Country\Collection $countryCollection)
- {
- $this->_countryCollection = $countryCollection;
- }
- /**
- * Return options array
- *
- * @param boolean $isMultiselect
- * @param string|array $foregroundCountries
- * @return array
- */
- public function toOptionArray($isMultiselect = false, $foregroundCountries = '')
- {
- if (!$this->_options) {
- $this->_options = $this->_countryCollection->loadData()->setForegroundCountries(
- $foregroundCountries
- )->toOptionArray(
- false
- );
- }
- $options = $this->_options;
- if (!$isMultiselect) {
- array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
- }
- return $options;
- }
- }
|