Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Value.php
Go to the documentation of this file.
1 <?php
7 
28 class Value extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\App\Config\ValueInterface
29 {
35  protected $_eventPrefix = 'config_data';
36 
44  protected $_eventObject = 'config_data';
45 
49  protected $_config;
50 
54  protected $cacheTypeList;
55 
65  public function __construct(
66  \Magento\Framework\Model\Context $context,
67  \Magento\Framework\Registry $registry,
69  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
70  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
71  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
72  array $data = []
73  ) {
74  $this->_config = $config;
75  $this->cacheTypeList = $cacheTypeList;
76  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
77  }
78 
84  public function isValueChanged()
85  {
86  return $this->getValue() != $this->getOldValue();
87  }
88 
94  public function getOldValue()
95  {
96  return (string)$this->_config->getValue(
97  $this->getPath(),
98  $this->getScope() ?: ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
99  $this->getScopeCode()
100  );
101  }
102 
109  public function getFieldsetDataValue($key)
110  {
111  $data = $this->_getData('fieldset_data');
112  return is_array($data) && isset($data[$key]) ? $data[$key] : null;
113  }
114 
122  public function afterSave()
123  {
124  if ($this->isValueChanged()) {
125  $this->cacheTypeList->invalidate(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER);
126  }
127 
128  return parent::afterSave();
129  }
130 
138  public function afterDelete()
139  {
140  $this->cacheTypeList->invalidate(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER);
141 
142  return parent::afterDelete();
143  }
144 }
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Value.php:65
getValue( $path=null, $scope=ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode=null)
Definition: Config.php:56