scope = $scope; $this->configStructureFactory = $structureFactory; $this->configValueFactory = $valueFactory; $this->jsonSerializer = $jsonSerializer; } /** * Processes value to display using backend model. * * @param string $scope The scope of configuration. E.g. 'default', 'website' or 'store' * @param string $scopeCode The scope code of configuration * @param string $value The value to process * @param string $path The configuration path for getting backend model. E.g. scope_id/group_id/field_id * @return string processed value result * @since 101.0.0 */ public function process($scope, $scopeCode, $value, $path) { $areaScope = $this->scope->getCurrentScope(); $this->scope->setCurrentScope(Area::AREA_ADMINHTML); /** @var Structure $configStructure */ $configStructure = $this->configStructureFactory->create(); $this->scope->setCurrentScope($areaScope); /** @var Field $field */ $field = $configStructure->getElementByConfigPath($path); /** @var Value $backendModel */ $backendModel = $field instanceof Field && $field->hasBackendModel() ? $field->getBackendModel() : $this->configValueFactory->create(); if ($backendModel instanceof Encrypted) { return $value ? self::SAFE_PLACEHOLDER : null; } $backendModel->setPath($path); $backendModel->setScope($scope); $backendModel->setScopeId($scopeCode); $backendModel->setValue($value); $backendModel->afterLoad(); $processedValue = $backendModel->getValue(); /** * If $processedValue is array it means that $value is json array (string). * It should be converted to string for displaying. */ return is_array($processedValue) ? $this->jsonSerializer->serialize($processedValue) : $processedValue; } }