![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/Ui/DataProvider/Model/Form/Modifier/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See COPYING.txt for license details. */ namespace Ecombricks\Ui\DataProvider\Model\Form\Modifier; /** * Model form data provider abstract modifier */ abstract class AbstractModifier implements \Magento\Ui\DataProvider\Modifier\ModifierInterface { use \Ecombricks\Ui\DataProvider\Modifier\ModifierTrait; /** * Data scope */ const DATA_SCOPE = 'data'; /** * Container prefix */ const CONTAINER_PREFIX = 'container_'; /** * Meta config path */ const META_CONFIG_PATH = '/arguments/data/config'; /** * Registry * * @var \Magento\Framework\Registry */ protected $registry; /** * Model config * * @var \Ecombricks\Framework\Model\ConfigInterface */ protected $modelConfig; /** * Constructor * * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Stdlib\ArrayManager $arrayManager * @param \Ecombricks\Framework\Model\ConfigInterface $modelConfig * @return void */ public function __construct( \Magento\Framework\Registry $registry, \Magento\Framework\Stdlib\ArrayManager $arrayManager, \Ecombricks\Framework\Model\ConfigInterface $modelConfig ) { $this->registry = $registry; $this->arrayManager = $arrayManager; $this->modelConfig = $modelConfig; } /** * Get model * * @return \Magento\Framework\Model\AbstractModel */ public function getModel() { return $this->registry->registry($this->modelConfig->getKey()); } /** * Get model ID * * @return int|null */ public function getModelId() { return $this->getModel()->getId(); } /** * Initialize model data * * @return $this */ protected function initializeModelData() { $modelId = $this->getModelId(); if (!isset($this->data[$modelId])) { $this->data[$modelId] = []; } return $this; } /** * Check if has model data * * @param string $path * @return bool */ protected function hasModelData($path) { $this->initializeModelData(); return $this->arrayManager->exists($path, $this->data[$this->getModelId()]); } /** * Get model data * * @param string $path */ protected function getModelData($path) { $this->initializeModelData(); return $this->arrayManager->get($path, $this->data[$this->getModelId()]); } /** * Set model data * * @param array $data * @param string $path * @return $this */ protected function setModelData($data, $path) { $this->initializeModelData(); $modelId = $this->getModelId(); $this->data[$modelId] = $this->arrayManager->set($path, $this->data[$modelId], $data); return $this; } /** * Remove model data * * @param string $path * @return $this */ protected function removeModelData($path) { $this->initializeModelData(); $modelId = $this->getModelId(); $this->data[$modelId] = $this->arrayManager->remove($path, $this->data[$modelId]); return $this; } /** * Set model field value * * @param string $fieldName * @param mixed|null $value * @return $this */ protected function setModelFieldValue($fieldName, $value = null) { if (!$this->hasModelData($fieldName)) { $this->setModelData($value !== null ? $value : $this->getModel()->getData($fieldName), $fieldName); } return $this; } }