Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Physical.php
Go to the documentation of this file.
1 <?php
11 
13 {
19  protected $_theme;
20 
24  protected $_themeFactory;
25 
29  protected $_themeCopyService;
30 
34  protected $_themeCollection;
35 
42  public function __construct(
43  \Magento\Framework\View\Design\ThemeInterface $theme,
44  \Magento\Theme\Model\ThemeFactory $themeFactory,
45  \Magento\Theme\Model\CopyService $themeCopyService,
46  \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection
47  ) {
48  $this->_theme = $theme;
49  $this->_themeFactory = $themeFactory;
50  $this->_themeCopyService = $themeCopyService;
51  $this->_themeCollection = $themeCollection;
52  }
53 
60  public function createVirtualTheme($theme)
61  {
62  $themeData = $theme->getData();
63  $themeData['parent_id'] = $theme->getId();
64  $themeData['theme_id'] = null;
65  $themeData['theme_path'] = null;
66  $themeData['theme_title'] = $this->_getVirtualThemeTitle($theme);
68 
70  $themeCustomization = $this->_themeFactory->create()->setData($themeData);
71  $themeCustomization->getThemeImage()->createPreviewImageCopy($theme);
72  $themeCustomization->save();
73 
74  $this->_themeCopyService->copy($theme, $themeCustomization);
75 
76  return $themeCustomization;
77  }
78 
85  protected function _getVirtualThemeTitle($theme)
86  {
87  $themeCopyCount = $this->_themeCollection->addAreaFilter(
88  \Magento\Framework\App\Area::AREA_FRONTEND
89  )->addTypeFilter(
91  )->addFilter(
92  'parent_id',
93  $theme->getId()
94  )->count();
95 
96  $title = sprintf("%s - %s #%s", $theme->getThemeTitle(), __('Copy'), $themeCopyCount + 1);
97  return $title;
98  }
99 }
$title
Definition: default.phtml:14
__()
Definition: __.php:13
__construct(\Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Theme\Model\ThemeFactory $themeFactory, \Magento\Theme\Model\CopyService $themeCopyService, \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection)
Definition: Physical.php:42
$theme