11
11
use Magento \Cms \Api \Data \BlockInterface ;
12
12
use Magento \Framework \Exception \NoSuchEntityException ;
13
13
use Magento \Widget \Model \Template \FilterEmulate ;
14
+ use Magento \Framework \App \State ;
14
15
15
16
/**
16
17
* Cms block data provider
@@ -27,16 +28,24 @@ class Block
27
28
*/
28
29
private $ widgetFilter ;
29
30
31
+ /**
32
+ * @var State
33
+ */
34
+ private $ state ;
35
+
30
36
/**
31
37
* @param BlockRepositoryInterface $blockRepository
32
38
* @param FilterEmulate $widgetFilter
39
+ * @param State $state
33
40
*/
34
41
public function __construct (
35
42
BlockRepositoryInterface $ blockRepository ,
36
- FilterEmulate $ widgetFilter
43
+ FilterEmulate $ widgetFilter ,
44
+ State $ state
37
45
) {
38
46
$ this ->blockRepository = $ blockRepository ;
39
47
$ this ->widgetFilter = $ widgetFilter ;
48
+ $ this ->state = $ state ;
40
49
}
41
50
42
51
/**
@@ -56,7 +65,11 @@ public function getData(string $blockIdentifier): array
56
65
);
57
66
}
58
67
59
- $ renderedContent = $ this ->widgetFilter ->filter ($ block ->getContent ());
68
+ $ renderedContent = $ this ->state ->emulateAreaCode (
69
+ 'frontend ' ,
70
+ [$ this , 'getRenderedBlockContent ' ],
71
+ [$ block ->getContent ()]
72
+ );
60
73
61
74
$ blockData = [
62
75
BlockInterface::BLOCK_ID => $ block ->getId (),
@@ -66,4 +79,14 @@ public function getData(string $blockIdentifier): array
66
79
];
67
80
return $ blockData ;
68
81
}
82
+
83
+ /**
84
+ * @param string $blockContent
85
+ *
86
+ * @return string
87
+ */
88
+ public function getRenderedBlockContent (string $ blockContent ) : string
89
+ {
90
+ return $ this ->widgetFilter ->filter ($ blockContent );
91
+ }
69
92
}
0 commit comments