File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ namespace Magento \Theme \Controller \Result ;
7+
8+ /**
9+ * Plugin for putting messages to cookies
10+ */
11+ class JsFooterPlugin
12+ {
13+ /**
14+ * Put all javascript to footer before sending the response
15+ *
16+ * @param \Magento\Framework\App\Response\Http $subject
17+ * @return void
18+ */
19+ public function beforeSendResponse (\Magento \Framework \App \Response \Http $ subject )
20+ {
21+ $ content = $ subject ->getContent ();
22+ $ script = [];
23+ if (strpos ($ content , '</body ' ) !== false ) {
24+ $ pattern = '#<script[^>]*+(?<!text/x-magento-template.)>.*?</script>#is ' ;
25+ $ content = preg_replace_callback (
26+ $ pattern ,
27+ function ($ matchPart ) use (&$ script ) {
28+ $ script [] = $ matchPart [0 ];
29+ return '' ;
30+ },
31+ $ content
32+ );
33+ $ subject ->setContent (
34+ str_replace ('</body ' , implode ("\n" , $ script ) . "\n</body " , $ content )
35+ );
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change 2626 <type name =" Magento\Framework\Controller\ResultInterface" >
2727 <plugin name =" result-messages" type =" Magento\Theme\Controller\Result\MessagePlugin" />
2828 </type >
29+ <type name =" Magento\Framework\App\Response\Http" >
30+ <plugin name =" result-js-footer" type =" Magento\Theme\Controller\Result\JsFooterPlugin" />
31+ </type >
2932</config >
You can’t perform that action at this time.
0 commit comments