Block.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Cms\Model\Config\Source;
  8. use Magento\Cms\Model\ResourceModel\Block\CollectionFactory;
  9. use Magento\Framework\Data\OptionSourceInterface;
  10. /**
  11. * Class Block
  12. */
  13. class Block implements OptionSourceInterface
  14. {
  15. /**
  16. * @var array
  17. */
  18. private $options;
  19. /**
  20. * @var \Magento\Cms\Model\ResourceModel\Block\CollectionFactory
  21. */
  22. private $collectionFactory;
  23. /**
  24. * @param \Magento\Cms\Model\ResourceModel\Block\CollectionFactory $collectionFactory
  25. */
  26. public function __construct(
  27. CollectionFactory $collectionFactory
  28. ) {
  29. $this->collectionFactory = $collectionFactory;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function toOptionArray()
  35. {
  36. if (!$this->options) {
  37. $this->options = $this->collectionFactory->create()->toOptionIdArray();
  38. }
  39. return $this->options;
  40. }
  41. }