/
Region.php
55 lines (50 loc) · 1.73 KB
/
Region.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Customer region attribute source
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;
class Region extends \Magento\Eav\Model\Entity\Attribute\Source\Table
{
/**
* @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory
*/
protected $_regionsFactory;
/**
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
* @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionsFactory
*/
public function __construct(
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
\Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionsFactory
) {
$this->_regionsFactory = $regionsFactory;
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
}
/**
* Retrieve all region options
*
* @return array
*/
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->_createRegionsCollection()->load()->toOptionArray();
}
return $this->_options;
}
/**
* @return \Magento\Directory\Model\ResourceModel\Region\Collection
*/
protected function _createRegionsCollection()
{
return $this->_regionsFactory->create();
}
}