Themes.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;
  7. use Magento\Framework\Data\OptionSourceInterface;
  8. use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
  9. /**
  10. * Option source of the widget theme property.
  11. *
  12. * Can be used as a data provider for UI components that shows possible themes as a list.
  13. */
  14. class Themes implements OptionSourceInterface
  15. {
  16. /**
  17. * @var ThemeCollectionFactory
  18. */
  19. private $themeCollectionFactory;
  20. /**
  21. * @param ThemeCollectionFactory $themeCollectionFactory
  22. */
  23. public function __construct(ThemeCollectionFactory $themeCollectionFactory)
  24. {
  25. $this->themeCollectionFactory = $themeCollectionFactory;
  26. }
  27. /**
  28. * Return array of options as value-label pairs
  29. *
  30. * @return array Format: array('<theme ID>' => '<theme label>', ...)
  31. */
  32. public function toOptionArray()
  33. {
  34. // Load only visible themes that are used in frontend area
  35. return $this->themeCollectionFactory->create()->loadRegisteredThemes()->toOptionHash();
  36. }
  37. }