Skip to content

Commit

Permalink
Remove unneeded internal caching of options
Browse files Browse the repository at this point in the history
  • Loading branch information
ajardin authored and Amol Chaudhari committed Jan 27, 2019
1 parent bf13289 commit eb6f0e6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
*/
protected $pageLayoutBuilder;

/**
* @inheritdoc
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $_options = null;

/**
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
*/
Expand All @@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
}
return $this->_options;
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
$this->_options = $options;

return $options;
}
}
18 changes: 12 additions & 6 deletions app/code/Magento/Catalog/Model/Product/Attribute/Source/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
*/
protected $pageLayoutBuilder;

/**
* @inheritdoc
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $_options = null;

/**
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
*/
Expand All @@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
}

/**
* @return array
* @inheritdoc
*/
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
}
return $this->_options;
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
$this->_options = $options;

return $options;
}
}
11 changes: 3 additions & 8 deletions app/code/Magento/Cms/Model/Page/Source/PageLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PageLayout implements OptionSourceInterface

/**
* @var array
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
*/
protected $options;

Expand All @@ -34,16 +35,10 @@ public function __construct(BuilderInterface $pageLayoutBuilder)
}

/**
* Get options
*
* @return array
* @inheritdoc
*/
public function toOptionArray()
{
if ($this->options !== null) {
return $this->options;
}

$configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
$options = [];
foreach ($configOptions as $key => $value) {
Expand All @@ -54,6 +49,6 @@ public function toOptionArray()
}
$this->options = $options;

return $this->options;
return $options;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Theme/Model/PageLayout/Config/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
}

/**
* @return \Magento\Framework\View\PageLayout\Config
* @inheritdoc
*/
public function getPageLayoutsConfig()
{
Expand All @@ -61,7 +61,7 @@ public function getPageLayoutsConfig()
*/
protected function getConfigFiles()
{
if (empty($this->configFiles)) {
if (!$this->configFiles) {
$configFiles = [];
foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
$configFiles[] = $this->fileCollector->getFilesContent($theme, 'layouts.xml');
Expand Down

0 comments on commit eb6f0e6

Please sign in to comment.