forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request magento#2620 from magento-thunder/MAGETWO-92154
Fixed issues: - MAGETWO-92154: [Backport to 2.2] Unlock Locales Editing when SCD on Demand Mode is Enabled
- Loading branch information
Showing
10 changed files
with
683 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
app/code/Magento/Config/Model/Config/Structure/ElementVisibility/ConcealInProduction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Config\Model\Config\Structure\ElementVisibility; | ||
|
||
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface; | ||
use Magento\Framework\App\State; | ||
|
||
/** | ||
* Defines status of visibility of form elements on Stores > Settings > Configuration page | ||
* in Admin Panel in Production mode. | ||
* @api | ||
*/ | ||
class ConcealInProduction implements ElementVisibilityInterface | ||
{ | ||
/** | ||
* The list of form element paths with concrete visibility status. | ||
* | ||
* E.g. | ||
* | ||
* ```php | ||
* [ | ||
* 'general/locale/code' => ElementVisibilityInterface::DISABLED, | ||
* 'general/country' => ElementVisibilityInterface::HIDDEN, | ||
* ]; | ||
* ``` | ||
* | ||
* It means that: | ||
* - field Locale (in group Locale Options in section General) will be disabled | ||
* - group Country Options (in section General) will be hidden | ||
* | ||
* @var array | ||
*/ | ||
private $configs = []; | ||
|
||
/** | ||
* The object that has information about the state of the system. | ||
* | ||
* @var State | ||
*/ | ||
private $state; | ||
|
||
/** | ||
* | ||
* The list of form element paths which ignore visibility status. | ||
* | ||
* E.g. | ||
* | ||
* ```php | ||
* [ | ||
* 'general/country/default' => '', | ||
* ]; | ||
* ``` | ||
* | ||
* It means that: | ||
* - field 'default' in group Country Options (in section General) will be showed, even if all group(section) | ||
* will be hidden. | ||
* | ||
* @var array | ||
*/ | ||
private $exemptions = []; | ||
|
||
/** | ||
* @param State $state The object that has information about the state of the system | ||
* @param array $configs The list of form element paths with concrete visibility status. | ||
* @param array $exemptions The list of form element paths which ignore visibility status. | ||
*/ | ||
public function __construct(State $state, array $configs = [], array $exemptions = []) | ||
{ | ||
$this->state = $state; | ||
$this->configs = $configs; | ||
$this->exemptions = $exemptions; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @since 100.2.0 | ||
*/ | ||
public function isHidden($path) | ||
{ | ||
$path = $this->normalizePath($path); | ||
if ($this->state->getMode() === State::MODE_PRODUCTION | ||
&& preg_match('/(?<group>(?<section>.*?)\/.*?)\/.*?/', $path, $match)) { | ||
$group = $match['group']; | ||
$section = $match['section']; | ||
$exemptions = array_keys($this->exemptions); | ||
$checkedItems = []; | ||
foreach ([$path, $group, $section] as $itemPath) { | ||
$checkedItems[] = $itemPath; | ||
if (!empty($this->configs[$itemPath])) { | ||
return $this->configs[$itemPath] === static::HIDDEN | ||
&& empty(array_intersect($checkedItems, $exemptions)); | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @since 100.2.0 | ||
*/ | ||
public function isDisabled($path) | ||
{ | ||
$path = $this->normalizePath($path); | ||
if ($this->state->getMode() === State::MODE_PRODUCTION) { | ||
while (true) { | ||
if (!empty($this->configs[$path])) { | ||
return $this->configs[$path] === static::DISABLED; | ||
} | ||
|
||
$position = strripos($path, '/'); | ||
if ($position === false) { | ||
break; | ||
} | ||
$path = substr($path, 0, $position); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Returns normalized path. | ||
* | ||
* @param string $path The path to be normalized | ||
* @return string The normalized path | ||
*/ | ||
private function normalizePath($path) | ||
{ | ||
return trim($path, '/'); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...Config/Model/Config/Structure/ElementVisibility/ConcealInProductionWithoutScdOnDemand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Config\Model\Config\Structure\ElementVisibility; | ||
|
||
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface; | ||
use Magento\Framework\App\DeploymentConfig; | ||
use Magento\Framework\Config\ConfigOptionsListConstants as Constants; | ||
|
||
/** | ||
* Defines status of visibility of form elements on Stores > Settings > Configuration page | ||
* when Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION is enabled | ||
* otherwise rule from Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction is used | ||
* @see \Magento\Config\Model\Config\Structure\ElementVisibility\ConcealInProduction | ||
* | ||
* @api | ||
*/ | ||
class ConcealInProductionWithoutScdOnDemand implements ElementVisibilityInterface | ||
{ | ||
/** | ||
* @var ConcealInProduction Element visibility rules in the Production mode | ||
*/ | ||
private $concealInProduction; | ||
|
||
/** | ||
* @var DeploymentConfig The application deployment configuration | ||
*/ | ||
private $deploymentConfig; | ||
|
||
/** | ||
* @param ConcealInProductionFactory $concealInProductionFactory | ||
* @param DeploymentConfig $deploymentConfig Deployment configuration reader | ||
* @param array $configs The list of form element paths with concrete visibility status. | ||
* @param array $exemptions The list of form element paths which ignore visibility status. | ||
*/ | ||
public function __construct( | ||
ConcealInProductionFactory $concealInProductionFactory, | ||
DeploymentConfig $deploymentConfig, | ||
array $configs = [], | ||
array $exemptions = [] | ||
) { | ||
$this->concealInProduction = $concealInProductionFactory | ||
->create(['configs' => $configs, 'exemptions' => $exemptions]); | ||
$this->deploymentConfig = $deploymentConfig; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isHidden($path): bool | ||
{ | ||
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { | ||
return $this->concealInProduction->isHidden($path); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isDisabled($path): bool | ||
{ | ||
if (!$this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)) { | ||
return $this->concealInProduction->isDisabled($path); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.