Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Enabled.php
Go to the documentation of this file.
1 <?php
7 
17 
21 class Enabled extends Value
22 {
26  const XML_ENABLED_CONFIG_STRUCTURE_PATH = 'analytics/general/enabled';
27 
33  private $subscriptionHandler;
34 
45  public function __construct(
46  Context $context,
50  SubscriptionHandler $subscriptionHandler,
52  AbstractDb $resourceCollection = null,
53  array $data = []
54  ) {
55  $this->subscriptionHandler = $subscriptionHandler;
56  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
57  }
58 
65  public function afterSave()
66  {
67  try {
68  if ($this->isValueChanged()) {
69  $enabled = $this->getData('value');
70  $enabled ? $this->subscriptionHandler->processEnabled() : $this->subscriptionHandler->processDisabled();
71  }
72  } catch (\Exception $e) {
73  $this->_logger->error($e->getMessage());
74  throw new LocalizedException(__('There was an error save new configuration value.'));
75  }
76 
77  return parent::afterSave();
78  }
79 }
getData($key='', $index=null)
Definition: DataObject.php:119
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
__construct(Context $context, Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, SubscriptionHandler $subscriptionHandler, AbstractResource $resource=null, AbstractDb $resourceCollection=null, array $data=[])
Definition: Enabled.php:45