Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Virtual.php
Go to the documentation of this file.
1 <?php
11 
13 {
19  protected $_theme;
20 
24  protected $_themeFactory;
25 
31  protected $_stagingTheme;
32 
36  protected $_themeCopyService;
37 
44 
51  public function __construct(
52  \Magento\Framework\View\Design\ThemeInterface $theme,
53  \Magento\Theme\Model\ThemeFactory $themeFactory,
54  \Magento\Theme\Model\CopyService $themeCopyService,
55  \Magento\Theme\Model\Config\Customization $customizationConfig
56  ) {
57  $this->_theme = $theme;
58  $this->_themeFactory = $themeFactory;
59  $this->_themeCopyService = $themeCopyService;
60  $this->_customizationConfig = $customizationConfig;
61  }
62 
68  public function getStagingTheme()
69  {
70  if (!$this->_stagingTheme) {
71  $this->_stagingTheme = $this->_theme->getStagingVersion();
72  if (!$this->_stagingTheme) {
73  $this->_stagingTheme = $this->_createStagingTheme();
74  $this->_themeCopyService->copy($this->_theme, $this->_stagingTheme);
75  }
76  }
77  return $this->_stagingTheme;
78  }
79 
85  public function getPhysicalTheme()
86  {
88  $parentTheme = $this->_theme->getParentTheme();
89  while ($parentTheme && !$parentTheme->isPhysical()) {
90  $parentTheme = $parentTheme->getParentTheme();
91  }
92 
93  if (!$parentTheme || !$parentTheme->getId()) {
94  return null;
95  }
96 
97  return $parentTheme;
98  }
99 
105  public function isAssigned()
106  {
107  return $this->_customizationConfig->isThemeAssignedToStore($this->_theme);
108  }
109 
115  protected function _createStagingTheme()
116  {
117  $stagingTheme = $this->_themeFactory->create();
118  $stagingTheme->setData(
119  [
120  'parent_id' => $this->_theme->getId(),
121  'theme_path' => null,
122  'theme_title' => sprintf('%s - Staging', $this->_theme->getThemeTitle()),
123  'preview_image' => $this->_theme->getPreviewImage(),
124  'is_featured' => $this->_theme->getIsFeatured(),
126  ]
127  );
128  $stagingTheme->save();
129  return $stagingTheme;
130  }
131 }
__construct(\Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Theme\Model\ThemeFactory $themeFactory, \Magento\Theme\Model\CopyService $themeCopyService, \Magento\Theme\Model\Config\Customization $customizationConfig)
Definition: Virtual.php:51
$theme