1818
1919namespace Magento \Cms \Observer ;
2020
21- use Magento \Catalog \Model \Product ;
2221use Magento \Cms \Model \Page ;
2322use Magento \Framework \App \Cache \Type \Layout as LayoutCache ;
2423use Magento \Framework \App \Cache \StateInterface as CacheState ;
2524use Magento \Framework \App \Cache \Tag \Resolver ;
2625use Magento \Framework \Event \Observer ;
2726use Magento \Framework \Event \ObserverInterface ;
28- use Magento \Widget \Model \Widget \ Instance ;
27+ use Magento \Framework \Model \AbstractModel ;
2928
3029/**
3130 * Invalidates layout cache.
@@ -81,7 +80,7 @@ public function execute(Observer $observer)
8180 return ;
8281 }
8382
84- if (!$ object ->dataHasChangedFor (Page::PAGE_LAYOUT )) {
83+ if (!$ object instanceof Page || ! $ object ->dataHasChangedFor (Page::PAGE_LAYOUT )) {
8584 return ;
8685 }
8786
@@ -95,25 +94,19 @@ public function execute(Observer $observer)
9594
9695 /**
9796 * Get additional tags
97+ *
98+ * @param AbstractModel $object
99+ * @return string
98100 */
99- public function getAdditionalTags ($ object ): string
101+ public function getAdditionalTags (AbstractModel $ object ): string
100102 {
101103 $ tag = '' ;
102104 if ($ object instanceof Page) {
103105 $ tag = sprintf (
104- '%s_%s ' ,
105- 'CMS_PAGE_VIEW_ID ' ,
106- str_replace ('- ' , '_ ' , strtoupper ($ object ->getIdentifier ()))
107- );
108- } elseif ($ object instanceof Product) {
109- $ tag = sprintf (
110- '%s ' ,
111- str_replace (
112- '{{ID}} ' ,
113- (string ) $ object ->getId (),
114- Instance::SINGLE_PRODUCT_LAYOUT_HANDLE
115- ),
116- );
106+ '%s_%s ' ,
107+ 'CMS_PAGE_VIEW_ID ' ,
108+ str_replace ('- ' , '_ ' , strtoupper ($ object ->getIdentifier ()))
109+ );
117110 }
118111 return $ tag ;
119112 }
0 commit comments