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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme;
/**
* Class Save
* @deprecated 100.2.0
*/
class Save extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
{
/**
* Save action
*
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute()
{
$redirectBack = (bool)$this->getRequest()->getParam('back', false);
$themeData = $this->getRequest()->getParam('theme');
$customCssData = $this->getRequest()->getParam('custom_css_content');
$removeJsFiles = (array)$this->getRequest()->getParam('js_removed_files');
$reorderJsFiles = array_keys($this->getRequest()->getParam('js_order', []));
/** @var $themeFactory \Magento\Framework\View\Design\Theme\FlyweightFactory */
$themeFactory = $this->_objectManager->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
/** @var $cssService \Magento\Theme\Model\Theme\Customization\File\CustomCss */
$cssService = $this->_objectManager->get(\Magento\Theme\Model\Theme\Customization\File\CustomCss::class);
/** @var $singleFile \Magento\Theme\Model\Theme\SingleFile */
$singleFile = $this->_objectManager->create(
\Magento\Theme\Model\Theme\SingleFile::class,
['fileService' => $cssService]
);
try {
if ($this->getRequest()->getPostValue()) {
/** @var $theme \Magento\Theme\Model\Theme */
if (!empty($themeData['theme_id'])) {
$theme = $themeFactory->create($themeData['theme_id']);
} else {
$parentTheme = $themeFactory->create($themeData['parent_id']);
$theme = $parentTheme->getDomainModel(
\Magento\Framework\View\Design\ThemeInterface::TYPE_PHYSICAL
)->createVirtualTheme(
$parentTheme
);
}
if ($theme && !$theme->isEditable()) {
throw new \Magento\Framework\Exception\LocalizedException(__('This theme is not editable.'));
}
$theme->addData($themeData);
if (isset($themeData['preview']['delete'])) {
$theme->getThemeImage()->removePreviewImage();
}
$theme->getThemeImage()->uploadPreviewImage('preview');
$theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL);
$theme->save();
$customization = $theme->getCustomization();
$customization->reorder(
\Magento\Framework\View\Design\Theme\Customization\File\Js::TYPE,
$reorderJsFiles
);
$customization->delete($removeJsFiles);
$singleFile->update($theme, $customCssData);
$this->messageManager->addSuccess(__('You saved the theme.'));
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->_getSession()->setThemeData($themeData);
$this->_getSession()->setThemeCustomCssData($customCssData);
$redirectBack = true;
} catch (\Exception $e) {
$this->messageManager->addError('The theme was not saved');
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
}
$redirectBack
? $this->_redirect('adminhtml/*/edit', ['id' => $theme->getId()])
: $this->_redirect('adminhtml/*/');
}
}