Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueProcessor.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Config\Model\Config\StructureFactory;
17 
25 {
29  const SAFE_PLACEHOLDER = '******';
30 
36  private $configStructureFactory;
37 
43  private $configValueFactory;
44 
50  private $scope;
51 
57  private $jsonSerializer;
58 
66  public function __construct(
67  ScopeInterface $scope,
68  StructureFactory $structureFactory,
69  ValueFactory $valueFactory,
70  JsonSerializer $jsonSerializer
71  ) {
72  $this->scope = $scope;
73  $this->configStructureFactory = $structureFactory;
74  $this->configValueFactory = $valueFactory;
75  $this->jsonSerializer = $jsonSerializer;
76  }
77 
88  public function process($scope, $scopeCode, $value, $path)
89  {
90  $areaScope = $this->scope->getCurrentScope();
91  $this->scope->setCurrentScope(Area::AREA_ADMINHTML);
93  $configStructure = $this->configStructureFactory->create();
94  $this->scope->setCurrentScope($areaScope);
95 
97  $field = $configStructure->getElementByConfigPath($path);
98 
100  $backendModel = $field && $field->hasBackendModel()
101  ? $field->getBackendModel()
102  : $this->configValueFactory->create();
103 
104  if ($backendModel instanceof Encrypted) {
105  return $value ? self::SAFE_PLACEHOLDER : null;
106  }
107 
108  $backendModel->setPath($path);
109  $backendModel->setScope($scope);
110  $backendModel->setScopeId($scopeCode);
111  $backendModel->setValue($value);
112  $backendModel->afterLoad();
113  $processedValue = $backendModel->getValue();
114 
119  return is_array($processedValue) ? $this->jsonSerializer->serialize($processedValue) : $processedValue;
120  }
121 }
__construct(ScopeInterface $scope, StructureFactory $structureFactory, ValueFactory $valueFactory, JsonSerializer $jsonSerializer)
$value
Definition: gender.phtml:16