Website.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Customer\Attribute\Source;
  7. /**
  8. * Customer website attribute source
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Website extends \Magento\Eav\Model\Entity\Attribute\Source\Table
  13. {
  14. /**
  15. * @var \Magento\Store\Model\System\Store
  16. */
  17. protected $_store;
  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\Store\Model\System\Store $store
  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\Store\Model\System\Store $store
  27. ) {
  28. parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
  29. $this->_store = $store;
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function getAllOptions($withEmpty = true, $defaultValues = false)
  35. {
  36. if (!$this->_options) {
  37. $this->_options = $this->_store->getWebsiteValuesForForm();
  38. }
  39. return $this->_options;
  40. }
  41. /**
  42. * @param int|string $value
  43. * @return string|false
  44. */
  45. public function getOptionText($value)
  46. {
  47. if (!$this->_options) {
  48. $this->_options = $this->getAllOptions();
  49. }
  50. foreach ($this->_options as $option) {
  51. if ($option['value'] == $value) {
  52. return $option['label'];
  53. }
  54. }
  55. return false;
  56. }
  57. }