Skip to content

Commit

Permalink
Merge branch '2.3-develop' of github.com:magento/magento2ce into MC-1…
Browse files Browse the repository at this point in the history
…5729
  • Loading branch information
slopukhov committed Apr 4, 2019
2 parents 5f0bf18 + 19c4a50 commit 6de67fd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/code/Magento/Theme/Controller/Result/JsFooterPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Controller\Result;

/**
* Plugin for putting messages to cookies
*/
class JsFooterPlugin
{
/**
* Put all javascript to footer before sending the response
*
* @param \Magento\Framework\App\Response\Http $subject
* @return void
*/
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
{
$content = $subject->getContent();
$script = [];
if (strpos($content, '</body') !== false) {
$pattern = '#<script[^>]*+(?<!text/x-magento-template.)>.*?</script>#is';
$content = preg_replace_callback(
$pattern,
function ($matchPart) use (&$script) {
$script[] = $matchPart[0];
return '';
},
$content
);
$subject->setContent(
str_replace('</body', implode("\n", $script) . "\n</body", $content)
);
}
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Theme/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<type name="Magento\Framework\Controller\ResultInterface">
<plugin name="result-messages" type="Magento\Theme\Controller\Result\MessagePlugin"/>
</type>
<type name="Magento\Framework\App\Response\Http">
<plugin name="result-js-footer" type="Magento\Theme\Controller\Result\JsFooterPlugin"/>
</type>
</config>

0 comments on commit 6de67fd

Please sign in to comment.