Skip to content

Commit d17f266

Browse files
Merge branch 'MAGETWO-15371' of https://github.corp.magento.com/magento-tango/magento2ce into MAGETWO-52010
2 parents 05adfad + f483e5f commit d17f266

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Config;
7+
8+
/**
9+
* Interface DesignResolverInterface
10+
* @api
11+
*/
12+
interface DesignResolverInterface extends FileResolverInterface
13+
{
14+
/**
15+
* Retrieve parent configs
16+
*
17+
* @param string $filename
18+
* @param string $scope
19+
* @return array
20+
*/
21+
public function getParents($filename, $scope);
22+
}

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

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
use Magento\Framework\Module\Dir\Reader;
1111
use Magento\Framework\Filesystem;
12+
use Magento\Framework\View\Design\ThemeInterface;
1213
use Magento\Framework\View\DesignInterface;
1314
use Magento\Framework\App\Filesystem\DirectoryList;
1415
use Magento\Framework\View\Design\FileResolution\Fallback\ResolverInterface;
1516
use Magento\Framework\View\Design\Fallback\RulePool;
1617

17-
class FileResolver implements \Magento\Framework\Config\FileResolverInterface
18+
/**
19+
* Class FileResolver
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
*/
22+
class FileResolver implements \Magento\Framework\Config\FileResolverInterface, DesignResolverInterface
1823
{
1924
/**
2025
* Module configuration file reader
@@ -117,4 +122,66 @@ public function get($filename, $scope)
117122
}
118123
return $iterator;
119124
}
125+
126+
/**
127+
* {@inheritdoc}
128+
*/
129+
public function getParents($filename, $scope)
130+
{
131+
switch ($scope) {
132+
case 'global':
133+
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
134+
$designPath = $this->resolver->resolve(
135+
RulePool::TYPE_FILE,
136+
'etc/view.xml',
137+
$this->area,
138+
$this->currentTheme
139+
);
140+
141+
if (file_exists($designPath)) {
142+
try {
143+
$iterator = $this->getParentConfigs($this->currentTheme, []);
144+
} catch (\Exception $e) {
145+
throw new \Magento\Framework\Exception\LocalizedException(
146+
new \Magento\Framework\Phrase('Could not read config file')
147+
);
148+
}
149+
}
150+
break;
151+
default:
152+
$iterator = $this->iteratorFactory->create([]);
153+
break;
154+
}
155+
156+
return $iterator;
157+
}
158+
159+
/**
160+
* Recursively add parent theme configs
161+
*
162+
* @param ThemeInterface $theme
163+
* @param array $iterator
164+
* @param int $index
165+
* @return array
166+
*/
167+
private function getParentConfigs(ThemeInterface $theme, array $iterator, $index = 0)
168+
{
169+
if ($theme->getParentTheme() && $theme->isPhysical()) {
170+
$parentDesignPath = $this->resolver->resolve(
171+
RulePool::TYPE_FILE,
172+
'etc/view.xml',
173+
$this->area,
174+
$theme->getParentTheme()
175+
);
176+
177+
$parentDom = new \DOMDocument;
178+
$parentDom->load($parentDesignPath);
179+
180+
$iterator[$index] = $parentDom->saveXML();
181+
182+
$iterator = $this->getParentConfigs($theme->getParentTheme(), $iterator, ++$index);
183+
}
184+
185+
return $iterator;
186+
}
120187
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
*/
1010
namespace Magento\Framework\Config;
1111

12-
use Magento\Framework\Config\Dom\UrnResolver;
13-
12+
/**
13+
* Class View
14+
*
15+
* @property DesignResolverInterface $_fileResolver
16+
*/
1417
class View extends \Magento\Framework\Config\Reader\Filesystem
1518
{
1619
/**
@@ -210,4 +213,23 @@ protected function initData()
210213
$this->data = $this->read();
211214
}
212215
}
216+
217+
/**
218+
* {@inheritdoc}
219+
*/
220+
public function read($scope = null)
221+
{
222+
$scope = $scope ?: $this->_defaultScope;
223+
$result = [];
224+
225+
$parents = (array)$this->_fileResolver->getParents($this->_fileName, $scope);
226+
// Sort parents desc
227+
krsort($parents);
228+
229+
foreach ($parents as $parent) {
230+
$result = array_replace_recursive($result, $this->_readFiles([$parent]));
231+
}
232+
233+
return array_replace_recursive($result, parent::read($scope));
234+
}
213235
}

0 commit comments

Comments
 (0)