Layout.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\Layout\Source;
  7. class Layout implements \Magento\Framework\Option\ArrayInterface
  8. {
  9. /**
  10. * @var \Magento\Theme\Model\Layout\Config
  11. */
  12. protected $_config;
  13. /**
  14. * @param \Magento\Theme\Model\Layout\Config $config
  15. */
  16. public function __construct(\Magento\Theme\Model\Layout\Config $config)
  17. {
  18. $this->_config = $config;
  19. }
  20. /**
  21. * Page layout options
  22. *
  23. * @var array
  24. */
  25. protected $_options = null;
  26. /**
  27. * Default option
  28. * @var string
  29. */
  30. protected $_defaultValue = null;
  31. /**
  32. * Retrieve page layout options
  33. *
  34. * @return array
  35. */
  36. public function getOptions()
  37. {
  38. if ($this->_options === null) {
  39. $this->_options = [];
  40. foreach ($this->_config->getPageLayouts() as $layout) {
  41. $this->_options[$layout->getCode()] = $layout->getLabel();
  42. if ($layout->getIsDefault()) {
  43. $this->_defaultValue = $layout->getCode();
  44. }
  45. }
  46. }
  47. return $this->_options;
  48. }
  49. /**
  50. * Retrieve page layout options array
  51. *
  52. * @param bool $withEmpty
  53. * @return array
  54. */
  55. public function toOptionArray($withEmpty = false)
  56. {
  57. $options = [];
  58. foreach ($this->getOptions() as $value => $label) {
  59. $options[] = ['label' => $label, 'value' => $value];
  60. }
  61. if ($withEmpty) {
  62. array_unshift($options, ['value' => '', 'label' => __('-- Please Select --')]);
  63. }
  64. return $options;
  65. }
  66. /**
  67. * Default options value getter
  68. * @return string
  69. */
  70. public function getDefaultValue()
  71. {
  72. $this->getOptions();
  73. return $this->_defaultValue;
  74. }
  75. }