Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Theme.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class Theme extends Value
11 {
17  protected $_design = null;
18 
24  const XML_PATH_INVALID_CACHES = 'design/invalid_caches';
25 
38  public function __construct(
39  \Magento\Framework\Model\Context $context,
40  \Magento\Framework\Registry $registry,
43  \Magento\Framework\View\DesignInterface $design,
44  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
45  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
46  array $data = []
47  ) {
48  $this->_design = $design;
49  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
50  }
51 
57  public function beforeSave()
58  {
59  if ('' != $this->getValue()) {
60  $design = clone $this->_design;
61  $design->setDesignTheme($this->getValue(), \Magento\Framework\App\Area::AREA_FRONTEND);
62  }
63  return parent::beforeSave();
64  }
65 
72  protected function invalidateCache($forceInvalidate = false)
73  {
74  $types = array_keys(
75  $this->_config->getValue(
76  self::XML_PATH_INVALID_CACHES,
78  )
79  );
80  if ($forceInvalidate || $this->isValueChanged()) {
81  $this->cacheTypeList->invalidate($types);
82  }
83  }
84 
88  public function getValue()
89  {
90  return $this->getData('value') !== null ? $this->getData('value') : '';
91  }
92 
100  public function afterSave()
101  {
102  $this->invalidateCache();
103  return parent::afterSave();
104  }
105 
109  public function afterDelete()
110  {
111  $this->invalidateCache(true);
112  return parent::afterDelete();
113  }
114 }
getData($key='', $index=null)
Definition: DataObject.php:119
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Theme.php:38
invalidateCache($forceInvalidate=false)
Definition: Theme.php:72