Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Usecustom.php
Go to the documentation of this file.
1 <?php
11 
16 class Usecustom extends \Magento\Framework\App\Config\Value
17 {
23  protected $_configWriter;
24 
35  public function __construct(
36  \Magento\Framework\Model\Context $context,
37  \Magento\Framework\Registry $registry,
39  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
40  \Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
41  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
42  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
43  array $data = []
44  ) {
45  $this->_configWriter = $configWriter;
46  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
47  }
48 
55  public function beforeSave()
56  {
57  $value = $this->getValue();
58  if ($value == 1) {
59  $customUrl = $this->getData('groups/url/fields/custom/value');
60  if (empty($customUrl)) {
61  throw new \Magento\Framework\Exception\LocalizedException(__('Please specify the admin custom URL.'));
62  }
63  }
64 
65  return $this;
66  }
67 
73  public function afterSave()
74  {
75  $value = $this->getValue();
76 
77  if (!$value) {
78  $this->_configWriter->delete(
82  );
83  $this->_configWriter->delete(
87  );
88  }
89 
90  return parent::afterSave();
91  }
92 }
getData($key='', $index=null)
Definition: DataObject.php:119
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Usecustom.php:35