Skip to content

Commit 1e1a487

Browse files
author
Bomko, Alex(abomko)
committed
Merge pull request #4 from magento-dragons/product-video-PR4
Product video pr4
2 parents 2236ab1 + 5fbd687 commit 1e1a487

File tree

4 files changed

+61
-51
lines changed

4 files changed

+61
-51
lines changed

app/code/Magento/ProductVideo/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<default>
1010
<catalog>
1111
<product_video>
12-
<play_if_base>1</play_if_base>
12+
<play_if_base>0</play_if_base>
1313
<show_related>0</show_related>
1414
<video_auto_restart>0</video_auto_restart>
1515
</product_video>

dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,31 +174,9 @@ public function getFilenameDataProvider()
174174
public function testGetViewConfig()
175175
{
176176
$this->_emulateFixtureTheme();
177-
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
178-
$theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
179-
'Magento\Framework\View\DesignInterface'
180-
)->getDesignTheme();
181-
$customConfigFile = $theme->getCustomization()->getCustomViewConfigPath();
182-
/** @var $filesystem \Magento\Framework\Filesystem */
183-
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
184-
->create('Magento\Framework\Filesystem');
185-
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
186-
$relativePath = $directory->getRelativePath($customConfigFile);
187-
try {
188-
$directory->writeFile(
189-
$relativePath,
190-
'<?xml version="1.0" encoding="UTF-8"?>
191-
<view><vars module="Namespace_Module"><var name="var">var value</var></vars></view>'
192-
);
193-
194-
$config = $this->_viewConfig->getViewConfig();
195-
$this->assertInstanceOf('Magento\Framework\Config\View', $config);
196-
$this->assertEquals('var value', $config->getVarValue('Namespace_Module', 'var'));
197-
} catch (\Exception $e) {
198-
$directory->delete($relativePath);
199-
throw $e;
200-
}
201-
$directory->delete($relativePath);
177+
$config = $this->_viewConfig->getViewConfig();
178+
$this->assertInstanceOf('Magento\Framework\Config\View', $config);
179+
$this->assertEquals(['var1' => 'value1', 'var2' => 'value2'], $config->getVars('Namespace_Module'));
202180
}
203181

204182
/**

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

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Filesystem;
1212
use Magento\Framework\View\DesignInterface;
1313
use Magento\Framework\App\Filesystem\DirectoryList;
14-
use Symfony\Component\Config\Definition\Exception\Exception;
14+
use Magento\Framework\Component\ComponentRegistrar;
1515

1616
class FileResolver implements \Magento\Framework\Config\FileResolverInterface
1717
{
@@ -43,25 +43,30 @@ class FileResolver implements \Magento\Framework\Config\FileResolverInterface
4343
protected $area;
4444

4545
/**
46-
* Root directory
47-
*
48-
* @var ReadInterface
46+
* @var Filesystem\Directory\ReadInterface
4947
*/
5048
protected $rootDirectory;
5149

50+
/**
51+
* @var \Magento\Framework\Component\ComponentRegistrar
52+
*/
53+
protected $componentRegistrar;
54+
5255
/**
5356
* @param Reader $moduleReader
5457
* @param FileIteratorFactory $iteratorFactory
5558
* @param DesignInterface $designInterface
5659
* @param DirectoryList $directoryList
5760
* @param Filesystem $filesystem
61+
* @param ComponentRegistrar $componentRegistrar
5862
*/
5963
public function __construct(
6064
Reader $moduleReader,
6165
FileIteratorFactory $iteratorFactory,
6266
DesignInterface $designInterface,
6367
DirectoryList $directoryList,
64-
Filesystem $filesystem
68+
Filesystem $filesystem,
69+
ComponentRegistrar $componentRegistrar
6570
) {
6671
$this->directoryList = $directoryList;
6772
$this->iteratorFactory = $iteratorFactory;
@@ -70,6 +75,7 @@ public function __construct(
7075
$this->themePath = $designInterface->getThemePath($this->currentTheme);
7176
$this->area = $designInterface->getArea();
7277
$this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
78+
$this->componentRegistrar = $componentRegistrar;
7379
}
7480

7581
/**
@@ -80,29 +86,32 @@ public function get($filename, $scope)
8086
switch ($scope) {
8187
case 'global':
8288
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
83-
8489
$themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
8590
if ($themeConfigFile
8691
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
8792
) {
88-
$iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile(
89-
$this->rootDirectory->getRelativePath($themeConfigFile)
90-
);
91-
}
92-
93-
$designPath =
94-
$this->directoryList->getPath(DirectoryList::APP)
95-
. '/design/'
96-
. $this->area
97-
. '/'
98-
. $this->themePath
99-
. '/etc/view.xml';
100-
if (file_exists($designPath)) {
101-
try {
102-
$designDom = new \DOMDocument;
103-
$designDom->load($designPath);
104-
$iterator[$designPath] = $designDom->saveXML();
105-
} catch (Exception $e) {
93+
$iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] =
94+
$this->rootDirectory->readFile(
95+
$this->rootDirectory->getRelativePath(
96+
$themeConfigFile
97+
)
98+
);
99+
} else {
100+
$designPath =
101+
$this->componentRegistrar->getPath(
102+
ComponentRegistrar::THEME,
103+
$this->area . '/' . $this->themePath
104+
) . '/etc/view.xml';
105+
if (file_exists($designPath)) {
106+
try {
107+
$designDom = new \DOMDocument;
108+
$designDom->load($designPath);
109+
$iterator[$designPath] = $designDom->saveXML();
110+
} catch (\Exception $e) {
111+
throw new \Magento\Framework\Exception\LocalizedException(
112+
new \Magento\Framework\Phrase('Could not read config file')
113+
);
114+
}
106115
}
107116
}
108117
break;

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class View extends \Magento\Framework\Config\Reader\Filesystem
1818
*/
1919
protected $xpath;
2020

21+
/**
22+
* View config data
23+
*
24+
* @var array
25+
*/
26+
protected $data;
27+
2128
/**
2229
* @param FileResolverInterface $fileResolver
2330
* @param ConverterInterface $converter
@@ -52,7 +59,6 @@ public function __construct(
5259
$domDocumentClass,
5360
$defaultScope
5461
);
55-
$this->data = $this->read();
5662
}
5763

5864
/**
@@ -65,6 +71,7 @@ public function __construct(
6571
*/
6672
public function getVars($module)
6773
{
74+
$this->initData();
6875
return isset($this->data['vars'][$module]) ? $this->data['vars'][$module] : [];
6976
}
7077

@@ -77,6 +84,7 @@ public function getVars($module)
7784
*/
7885
public function getVarValue($module, $var)
7986
{
87+
$this->initData();
8088
if (!isset($this->data['vars'][$module])) {
8189
return false;
8290
}
@@ -102,6 +110,7 @@ public function getVarValue($module, $var)
102110
*/
103111
public function getMediaEntities($module, $mediaType)
104112
{
113+
$this->initData();
105114
return isset($this->data['media'][$module][$mediaType]) ? $this->data['media'][$module][$mediaType] : [];
106115
}
107116

@@ -115,6 +124,7 @@ public function getMediaEntities($module, $mediaType)
115124
*/
116125
public function getMediaAttributes($module, $mediaType, $mediaId)
117126
{
127+
$this->initData();
118128
return isset($this->data['media'][$module][$mediaType][$mediaId])
119129
? $this->data['media'][$module][$mediaType][$mediaId]
120130
: [];
@@ -185,6 +195,19 @@ public function getExcludedDir()
185195
*/
186196
protected function getItems()
187197
{
198+
$this->initData();
188199
return isset($this->data['exclude']) ? $this->data['exclude'] : [];
189200
}
201+
202+
/**
203+
* Initialize data array
204+
*
205+
* @return void
206+
*/
207+
protected function initData()
208+
{
209+
if ($this->data === null) {
210+
$this->data = $this->read();
211+
}
212+
}
190213
}

0 commit comments

Comments
 (0)