Website.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config\Source;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Website implements \Magento\Framework\Option\ArrayInterface
  12. {
  13. /**
  14. * @var array
  15. */
  16. protected $_options;
  17. /**
  18. * @var \Magento\Store\Model\StoreManagerInterface
  19. */
  20. protected $_storeManager;
  21. /**
  22. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  23. */
  24. public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager)
  25. {
  26. $this->_storeManager = $storeManager;
  27. }
  28. /**
  29. * @return array
  30. */
  31. public function toOptionArray()
  32. {
  33. if (!$this->_options) {
  34. $this->_options = [];
  35. foreach ($this->_storeManager->getWebsites() as $website) {
  36. $id = $website->getId();
  37. $name = $website->getName();
  38. if ($id != 0) {
  39. $this->_options[] = ['value' => $id, 'label' => $name];
  40. }
  41. }
  42. }
  43. return $this->_options;
  44. }
  45. }