Skip to content

Commit

Permalink
Merge pull request #271 from magento-tango/MAGETWO-47054
Browse files Browse the repository at this point in the history
[Tango] Bug: BaseURL in Static View Files
  • Loading branch information
magicbunneh committed Dec 28, 2015
2 parents 6ca1cf3 + 4794293 commit 8ebcb63
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<script>
var BASE_URL = '<?php /* @escapeNotVerified */ echo $block->getUrl('*') ?>';
var FORM_KEY = '<?php /* @escapeNotVerified */ echo $block->getFormKey() ?>';
var require = {
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
};
</script>
12 changes: 0 additions & 12 deletions app/code/Magento/RequireJs/Block/Html/Head/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,4 @@ protected function _prepareLayout()

return parent::_prepareLayout();
}

/**
* Include base RequireJs configuration necessary for working with Magento application
*
* @return string|void
*/
protected function _toHtml()
{
return "<script type=\"text/javascript\">\n"
. $this->config->getBaseConfig()
. "</script>\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,4 @@ public function testSetLayout()
);
$object->setLayout($layout);
}

public function testToHtml()
{
$this->context->expects($this->once())
->method('getEventManager')
->will($this->returnValue($this->getMockForAbstractClass('\Magento\Framework\Event\ManagerInterface')));
$this->context->expects($this->once())
->method('getScopeConfig')
->will($this->returnValue(
$this->getMockForAbstractClass('\Magento\Framework\App\Config\ScopeConfigInterface')
));
$this->config->expects($this->once())->method('getBaseConfig')->will($this->returnValue('the config data'));
$this->minificationMock = $this->getMockBuilder('Magento\Framework\View\Asset\Minification')
->disableOriginalConstructor()
->getMock();

$object = new Config(
$this->context,
$this->config,
$this->fileManager,
$this->pageConfig,
$this->bundleConfig,
$this->minificationMock
);
$html = $object->toHtml();
$expectedFormat = <<<expected
<script type="text/javascript">
the config data</script>
expected;
$this->assertStringMatchesFormat($expectedFormat, $html);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Theme/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="default_head_blocks"/>
<body>
<block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
<referenceContainer name="after.body.start">
<block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config"/>
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<script>
var require = {
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
};
</script>
6 changes: 2 additions & 4 deletions lib/internal/Magento/Framework/RequireJs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Config
*/
const FULL_CONFIG_TEMPLATE = <<<config
(function(require){
%base%
%function%
%usages%
Expand Down Expand Up @@ -134,7 +133,6 @@ public function __construct(
public function getConfig()
{
$distributedConfig = '';
$baseConfig = $this->getBaseConfig();
$customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
foreach ($customConfigFiles as $file) {
/** @var $fileReader \Magento\Framework\Filesystem\File\Read */
Expand All @@ -148,8 +146,8 @@ public function getConfig()
}

$fullConfig = str_replace(
['%function%', '%base%', '%usages%'],
[$distributedConfig, $baseConfig],
['%function%', '%usages%'],
[$distributedConfig],
self::FULL_CONFIG_TEMPLATE
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function testGetConfig()

$expected = <<<expected
(function(require){
require.config({"baseUrl":""});
(function() {
file_one.js content
require.config(config);
Expand Down

0 comments on commit 8ebcb63

Please sign in to comment.