Edit.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Theme editor container
  8. */
  9. namespace Magento\Theme\Block\Adminhtml\System\Design\Theme;
  10. /**
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Edit extends \Magento\Backend\Block\Widget\Form\Container
  15. {
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry = null;
  22. /**
  23. * @param \Magento\Backend\Block\Widget\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Widget\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. array $data = []
  31. ) {
  32. $this->_coreRegistry = $registry;
  33. parent::__construct($context, $data);
  34. }
  35. /**
  36. * Prepare layout
  37. *
  38. * @return \Magento\Framework\View\Element\AbstractBlock
  39. */
  40. protected function _prepareLayout()
  41. {
  42. $this->_blockGroup = 'Magento_Theme';
  43. $this->_controller = 'Adminhtml_System_Design_Theme';
  44. $this->setId('theme_edit');
  45. if (is_object($this->getLayout()->getBlock('page.title'))) {
  46. $this->getLayout()->getBlock('page.title')->setPageTitle($this->getHeaderText());
  47. }
  48. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  49. $theme = $this->_getCurrentTheme();
  50. if ($theme) {
  51. if ($theme->isEditable()) {
  52. $this->buttonList->add(
  53. 'save_and_continue',
  54. [
  55. 'label' => __('Save and Continue Edit'),
  56. 'class' => 'save',
  57. 'data_attribute' => [
  58. 'mage-init' => [
  59. 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'],
  60. ],
  61. ]
  62. ],
  63. 1
  64. );
  65. } else {
  66. $this->buttonList->remove('save');
  67. $this->buttonList->remove('reset');
  68. }
  69. if ($theme->isDeletable()) {
  70. if ($theme->hasChildThemes()) {
  71. $message = __('Are you sure you want to delete this theme?');
  72. $onClick = sprintf(
  73. "deleteConfirm('%s', '%s')",
  74. $message,
  75. $this->getUrl('adminhtml/*/delete', ['id' => $theme->getId()])
  76. );
  77. $this->buttonList->update('delete', 'onclick', $onClick);
  78. }
  79. } else {
  80. $this->buttonList->remove('delete');
  81. }
  82. }
  83. return parent::_prepareLayout();
  84. }
  85. /**
  86. * Prepare header for container
  87. *
  88. * @return string
  89. */
  90. public function getHeaderText()
  91. {
  92. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  93. $theme = $this->_getCurrentTheme();
  94. if ($theme->getId()) {
  95. $header = __('Theme: %1', $theme->getThemeTitle());
  96. } else {
  97. $header = __('New Theme');
  98. }
  99. return $header;
  100. }
  101. /**
  102. * Get current theme
  103. *
  104. * @return \Magento\Theme\Model\Theme
  105. */
  106. protected function _getCurrentTheme()
  107. {
  108. return $this->_coreRegistry->registry('current_theme');
  109. }
  110. }