Skip to content

Commit b185332

Browse files
committed
Added Config class and changed constructor
1 parent 8e07181 commit b185332

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Model;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
12+
/**
13+
* Newsletter configuration model
14+
*/
15+
class Config
16+
{
17+
/**
18+
* Configuration path to newsletter active setting
19+
*/
20+
const XML_PATH_NEWSLETTER_ACTIVE = 'newsletter/general/active';
21+
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
protected $scopeConfig;
26+
27+
/**
28+
* Config constructor.
29+
*
30+
* @param ScopeConfigInterface $scopeConfig
31+
*/
32+
public function __construct(
33+
ScopeConfigInterface $scopeConfig
34+
) {
35+
$this->scopeConfig = $scopeConfig;
36+
}
37+
38+
/**
39+
* Returns newsletter's enabled status
40+
*
41+
* @return bool
42+
*/
43+
public function isActive($scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT)
44+
{
45+
return $this->scopeConfig->isSetFlag(self::XML_PATH_NEWSLETTER_ACTIVE, $scopeType);
46+
}
47+
}

app/code/Magento/Newsletter/Observer/PredispatchNewsletterObserver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\UrlInterface;
1414
use Magento\Store\Model\ScopeInterface;
1515
use Magento\Newsletter\Model\Config;
16+
use Magento\Framework\App\ObjectManager;
1617

1718
/**
1819
* Class PredispatchNewsletterObserver
@@ -39,16 +40,16 @@ class PredispatchNewsletterObserver implements ObserverInterface
3940
*
4041
* @param ScopeConfigInterface $scopeConfig
4142
* @param UrlInterface $url
42-
* @param Config $config
43+
* @param Config|null $config
4344
*/
4445
public function __construct(
4546
ScopeConfigInterface $scopeConfig,
4647
UrlInterface $url,
47-
Config $config
48+
Config $config = null
4849
) {
4950
$this->scopeConfig = $scopeConfig;
5051
$this->url = $url;
51-
$this->config = $config;
52+
$this->config = $config ?: ObjectManager::getInstance()->get(Config::class);
5253
}
5354

5455
/**

0 commit comments

Comments
 (0)