Skip to content

Commit 0b4cae3

Browse files
author
Bohdan Korablov
committed
MAGETWO-47054: BaseURL in Static View Files
1 parent 2c7cd74 commit 0b4cae3

File tree

7 files changed

+17
-48
lines changed

7 files changed

+17
-48
lines changed

app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<script>
88
var BASE_URL = '<?php /* @escapeNotVerified */ echo $block->getUrl('*') ?>';
99
var FORM_KEY = '<?php /* @escapeNotVerified */ echo $block->getFormKey() ?>';
10+
var require = {
11+
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
12+
};
1013
</script>

app/code/Magento/RequireJs/Block/Html/Head/Config.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,4 @@ protected function _prepareLayout()
119119

120120
return parent::_prepareLayout();
121121
}
122-
123-
/**
124-
* Include base RequireJs configuration necessary for working with Magento application
125-
*
126-
* @return string|void
127-
*/
128-
protected function _toHtml()
129-
{
130-
return "<script type=\"text/javascript\">\n"
131-
. $this->config->getBaseConfig()
132-
. "</script>\n";
133-
}
134122
}

app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,4 @@ public function testSetLayout()
131131
);
132132
$object->setLayout($layout);
133133
}
134-
135-
public function testToHtml()
136-
{
137-
$this->context->expects($this->once())
138-
->method('getEventManager')
139-
->will($this->returnValue($this->getMockForAbstractClass('\Magento\Framework\Event\ManagerInterface')));
140-
$this->context->expects($this->once())
141-
->method('getScopeConfig')
142-
->will($this->returnValue(
143-
$this->getMockForAbstractClass('\Magento\Framework\App\Config\ScopeConfigInterface')
144-
));
145-
$this->config->expects($this->once())->method('getBaseConfig')->will($this->returnValue('the config data'));
146-
$this->minificationMock = $this->getMockBuilder('Magento\Framework\View\Asset\Minification')
147-
->disableOriginalConstructor()
148-
->getMock();
149-
150-
$object = new Config(
151-
$this->context,
152-
$this->config,
153-
$this->fileManager,
154-
$this->pageConfig,
155-
$this->bundleConfig,
156-
$this->minificationMock
157-
);
158-
$html = $object->toHtml();
159-
$expectedFormat = <<<expected
160-
<script type="text/javascript">
161-
the config data</script>
162-
expected;
163-
$this->assertStringMatchesFormat($expectedFormat, $html);
164-
}
165134
}

app/code/Magento/Theme/view/frontend/layout/default.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<update handle="default_head_blocks"/>
1010
<body>
11+
<block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
1112
<referenceContainer name="after.body.start">
1213
<block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config"/>
1314
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
<script>
8+
var require = {
9+
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
10+
};
11+
</script>

lib/internal/Magento/Framework/RequireJs/Config.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class Config
5454
*/
5555
const FULL_CONFIG_TEMPLATE = <<<config
5656
(function(require){
57-
%base%
5857
%function%
5958
6059
%usages%
@@ -134,7 +133,6 @@ public function __construct(
134133
public function getConfig()
135134
{
136135
$distributedConfig = '';
137-
$baseConfig = $this->getBaseConfig();
138136
$customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
139137
foreach ($customConfigFiles as $file) {
140138
/** @var $fileReader \Magento\Framework\Filesystem\File\Read */
@@ -148,8 +146,8 @@ public function getConfig()
148146
}
149147

150148
$fullConfig = str_replace(
151-
['%function%', '%base%', '%usages%'],
152-
[$distributedConfig, $baseConfig],
149+
['%function%', '%usages%'],
150+
[$distributedConfig],
153151
self::FULL_CONFIG_TEMPLATE
154152
);
155153

lib/internal/Magento/Framework/RequireJs/Test/Unit/ConfigTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public function testGetConfig()
129129

130130
$expected = <<<expected
131131
(function(require){
132-
require.config({"baseUrl":""});
133132
(function() {
134133
file_one.js content
135134
require.config(config);

0 commit comments

Comments
 (0)