Themes.php 1.17 KB
Newer Older
Ketan's avatar
Ketan committed
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
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;

/**
 * Option source of the widget theme property.
 *
 * Can be used as a data provider for UI components that shows possible themes as a list.
 */
class Themes implements OptionSourceInterface
{
    /**
     * @var ThemeCollectionFactory
     */
    private $themeCollectionFactory;

    /**
     * @param ThemeCollectionFactory $themeCollectionFactory
     */
    public function __construct(ThemeCollectionFactory $themeCollectionFactory)
    {
        $this->themeCollectionFactory = $themeCollectionFactory;
    }

    /**
     * Return array of options as value-label pairs
     *
     * @return array Format: array('<theme ID>' => '<theme label>', ...)
     */
    public function toOptionArray()
    {
        // Load only visible themes that are used in frontend area
        return $this->themeCollectionFactory->create()->loadRegisteredThemes()->toOptionHash();
    }
}