@@ -88,8 +88,7 @@ public function render(array $params): array
88
88
89
89
if ($ block ->isActive ()) {
90
90
$ directiveResult = $ this ->widgetDirectiveRenderer ->render ($ params );
91
- $ result ['content ' ] = $ this ->removeScriptTags ($ directiveResult ['content ' ]);
92
- $ result ['error ' ] = $ directiveResult ['error ' ];
91
+ $ result = $ this ->removeScriptTags ($ directiveResult );
93
92
} else {
94
93
$ result ['error ' ] = __ ('Block disabled ' );
95
94
}
@@ -100,21 +99,26 @@ public function render(array $params): array
100
99
/**
101
100
* Remove script tag from html
102
101
*
103
- * @param string $html
104
- * @return string
102
+ * @param array $directiveResult
103
+ * @return array
105
104
*/
106
- private function removeScriptTags (string $ html ) : string
105
+ private function removeScriptTags (array $ directiveResult ): array
107
106
{
108
- $ dom = new \DOMDocument ();
109
- try {
110
- $ dom ->loadHTML ($ html );
111
- } catch (\Exception $ e ) {
112
- $ this ->loggerInterface ->critical ($ e ->getMessage ());
113
- return $ html ;
114
- }
115
- foreach (iterator_to_array ($ dom ->getElementsByTagName ('script ' )) as $ item ) {
116
- $ item ->parentNode ->removeChild ($ item );
117
- }
118
- return $ dom ->saveHTML ();
107
+ $ dom = new \DOMDocument ();
108
+ try {
109
+ $ dom ->loadHTML ($ directiveResult ['content ' ]);
110
+ } catch (\Exception $ e ) {
111
+ $ this ->loggerInterface ->critical ($ e ->getMessage ());
112
+ return [
113
+ 'error ' => __ ('The block cannot be displayed because it contains errors. ' )
114
+ ];
115
+ }
116
+ foreach (iterator_to_array ($ dom ->getElementsByTagName ('script ' )) as $ item ) {
117
+ $ item ->parentNode ->removeChild ($ item );
118
+ }
119
+ return [
120
+ 'content ' => $ dom ->saveHTML (),
121
+ 'error ' => $ directiveResult ['error ' ]
122
+ ];
119
123
}
120
124
}
0 commit comments