Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanThemeRelatedContentObserver.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Theme\Observer;
8 
12 
14 {
18  protected $themeImageFactory;
19 
23  protected $updateCollection;
24 
28  protected $themeConfig;
29 
35  public function __construct(
36  \Magento\Framework\View\Design\Theme\ImageFactory $themeImageFactory,
37  \Magento\Widget\Model\ResourceModel\Layout\Update\Collection $updateCollection,
38  \Magento\Theme\Model\Config\Customization $themeConfig
39  ) {
40  $this->themeImageFactory = $themeImageFactory;
41  $this->updateCollection = $updateCollection;
42  $this->themeConfig = $themeConfig;
43  }
44 
52  public function execute(EventObserver $observer)
53  {
54  $theme = $observer->getEvent()->getData('theme');
55  if (!($theme instanceof \Magento\Framework\View\Design\ThemeInterface)) {
56  return;
57  }
59  if ($this->themeConfig->isThemeAssignedToStore($theme)) {
60  throw new \Magento\Framework\Exception\LocalizedException(__('Theme isn\'t deletable.'));
61  }
62  $this->themeImageFactory->create(['theme' => $theme])->removePreviewImage();
63  $this->updateCollection->addThemeFilter($theme->getId())->delete();
64  }
65 }
__()
Definition: __.php:13
$theme