File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
app/code/Magento/Ui/Controller/Adminhtml/Index Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 9
9
use Magento \Ui \Controller \Adminhtml \AbstractAction ;
10
10
use Magento \Framework \View \Element \UiComponentFactory ;
11
11
use Magento \Framework \View \Element \UiComponentInterface ;
12
+ use Magento \Framework \View \Element \UiComponent \ContentType ;
12
13
13
14
/**
14
15
* Class Render
@@ -30,6 +31,7 @@ public function execute()
30
31
$ component = $ this ->factory ->create ($ this ->_request ->getParam ('namespace ' ));
31
32
$ this ->prepareComponent ($ component );
32
33
$ this ->_response ->appendBody ((string ) $ component ->render ());
34
+ $ this ->setResponseContentTypeHeader ($ component );
33
35
}
34
36
35
37
/**
@@ -45,4 +47,26 @@ protected function prepareComponent(UiComponentInterface $component)
45
47
}
46
48
$ component ->prepare ();
47
49
}
50
+
51
+ /**
52
+ * Set the response 'Content-Type' header based on the component's render engine
53
+ *
54
+ * @param UiComponentInterface $component
55
+ * @return void
56
+ */
57
+ private function setResponseContentTypeHeader (UiComponentInterface $ component )
58
+ {
59
+ $ contentType = 'text/html ' ;
60
+
61
+ if ($ component ->getContext ()) {
62
+ $ renderEngine = $ component ->getContext ()->getRenderEngine ();
63
+ if ($ renderEngine instanceof ContentType \Json) {
64
+ $ contentType = 'application/json ' ;
65
+ } elseif ($ renderEngine instanceof ContentType \Xml) {
66
+ $ contentType = 'application/xml ' ;
67
+ }
68
+ }
69
+
70
+ $ this ->_response ->setHeader ('Content-Type ' , $ contentType , true );
71
+ }
48
72
}
You can’t perform that action at this time.
0 commit comments