Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Config Class Reference

Public Member Functions

 __construct (\Magento\Framework\App\Config\ValueInterface $configData, \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Cache\FrontendInterface $configCache, \Magento\Framework\Cache\FrontendInterface $layoutCache)
 
 assignToStore ( $theme, array $stores=[], $scope=\Magento\Store\Model\ScopeInterface::SCOPE_STORES)
 

Protected Member Functions

 _getAssignedScopesCollection ($scope, $configPath)
 
 _unassignThemeFromStores ($themeId, $stores, $scope, &$isReassigned)
 
 _assignThemeToStores ($themeId, $stores, $scope, &$isReassigned)
 
 _assignThemeToDefaultScope ($themeId, &$isReassigned)
 

Protected Attributes

 $_configWriter
 
 $_configData
 
 $_storeManager
 
 $_eventManager
 
 $_configCache
 
 $_layoutCache
 

Detailed Description

Definition at line 14 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\Config\ValueInterface$configData
\Magento\Framework\App\Config\Storage\WriterInterface$configWriter
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Framework\Cache\FrontendInterface$configCache
\Magento\Framework\Cache\FrontendInterface$layoutCache

Definition at line 56 of file Config.php.

63  {
64  $this->_configData = $configData;
65  $this->_configWriter = $configWriter;
66  $this->_storeManager = $storeManager;
67  $this->_eventManager = $eventManager;
68  $this->_configCache = $configCache;
69  $this->_layoutCache = $layoutCache;
70  }
$layoutCache
Definition: layout_cache.php:8
$storeManager

Member Function Documentation

◆ _assignThemeToDefaultScope()

_assignThemeToDefaultScope (   $themeId,
$isReassigned 
)
protected

Assign theme to default scope

Parameters
string$themeId
bool&$isReassigned
Returns
$this

Definition at line 175 of file Config.php.

176  {
178  $this->_configWriter->save($configPath, $themeId, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
179  $isReassigned = true;
180  return $this;
181  }

◆ _assignThemeToStores()

_assignThemeToStores (   $themeId,
  $stores,
  $scope,
$isReassigned 
)
protected

Assign given theme to stores

Parameters
string$themeId
array$stores
string$scope
bool&$isReassigned
Returns
$this

Definition at line 156 of file Config.php.

157  {
159  if (count($stores) > 0) {
160  foreach ($stores as $storeId) {
161  $this->_configWriter->save($configPath, $themeId, $scope, $storeId);
162  $isReassigned = true;
163  }
164  }
165  return $this;
166  }

◆ _getAssignedScopesCollection()

_getAssignedScopesCollection (   $scope,
  $configPath 
)
protected

Get assigned scopes collection of a theme

Parameters
string$scope
string$configPath
Returns
\Magento\Config\Model\ResourceModel\Config\Data\Collection

Definition at line 115 of file Config.php.

116  {
117  return $this->_configData->getCollection()->addFieldToFilter(
118  'scope',
119  $scope
120  )->addFieldToFilter(
121  'path',
122  $configPath
123  );
124  }

◆ _unassignThemeFromStores()

_unassignThemeFromStores (   $themeId,
  $stores,
  $scope,
$isReassigned 
)
protected

Unassign given theme from stores that were unchecked

Parameters
string$themeId
array$stores
string$scope
bool&$isReassigned
Returns
$this

Definition at line 135 of file Config.php.

136  {
138  foreach ($this->_getAssignedScopesCollection($scope, $configPath) as $config) {
139  if ($config->getValue() == $themeId && !in_array($config->getScopeId(), $stores)) {
140  $this->_configWriter->delete($configPath, $scope, $config->getScopeId());
141  $isReassigned = true;
142  }
143  }
144  return $this;
145  }
$config
Definition: fraud_order.php:17
_getAssignedScopesCollection($scope, $configPath)
Definition: Config.php:115

◆ assignToStore()

assignToStore (   $theme,
array  $stores = [],
  $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES 
)

Assign theme to the stores

Parameters
\Magento\Framework\View\Design\ThemeInterface$theme
array$stores
string$scope
Returns
$this

Definition at line 80 of file Config.php.

84  {
85  $isReassigned = false;
86 
87  $this->_unassignThemeFromStores($theme->getId(), $stores, $scope, $isReassigned);
88 
89  if ($this->_storeManager->isSingleStoreMode()) {
90  $this->_assignThemeToDefaultScope($theme->getId(), $isReassigned);
91  } else {
92  $this->_assignThemeToStores($theme->getId(), $stores, $scope, $isReassigned);
93  }
94 
95  if ($isReassigned) {
96  $this->_configCache->clean();
97  $this->_layoutCache->clean();
98  }
99 
100  $this->_eventManager->dispatch(
101  'assign_theme_to_stores_after',
102  ['stores' => $stores, 'scope' => $scope, 'theme' => $theme]
103  );
104 
105  return $this;
106  }
_unassignThemeFromStores($themeId, $stores, $scope, &$isReassigned)
Definition: Config.php:135
_assignThemeToStores($themeId, $stores, $scope, &$isReassigned)
Definition: Config.php:156
$theme
_assignThemeToDefaultScope($themeId, &$isReassigned)
Definition: Config.php:175

Field Documentation

◆ $_configCache

$_configCache
protected

Definition at line 41 of file Config.php.

◆ $_configData

$_configData
protected

Definition at line 24 of file Config.php.

◆ $_configWriter

$_configWriter
protected

Definition at line 19 of file Config.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 36 of file Config.php.

◆ $_layoutCache

$_layoutCache
protected

Definition at line 46 of file Config.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 29 of file Config.php.


The documentation for this class was generated from the following file: