Region.php 1.7 KB

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