File tree Expand file tree Collapse file tree 2 files changed +51
-3
lines changed
app/code/Magento/Newsletter Expand file tree Collapse file tree 2 files changed +51
-3
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 13
13
use Magento \Framework \UrlInterface ;
14
14
use Magento \Store \Model \ScopeInterface ;
15
15
use Magento \Newsletter \Model \Config ;
16
+ use Magento \Framework \App \ObjectManager ;
16
17
17
18
/**
18
19
* Class PredispatchNewsletterObserver
@@ -39,16 +40,16 @@ class PredispatchNewsletterObserver implements ObserverInterface
39
40
*
40
41
* @param ScopeConfigInterface $scopeConfig
41
42
* @param UrlInterface $url
42
- * @param Config $config
43
+ * @param Config|null $config
43
44
*/
44
45
public function __construct (
45
46
ScopeConfigInterface $ scopeConfig ,
46
47
UrlInterface $ url ,
47
- Config $ config
48
+ Config $ config = null
48
49
) {
49
50
$ this ->scopeConfig = $ scopeConfig ;
50
51
$ this ->url = $ url ;
51
- $ this ->config = $ config ;
52
+ $ this ->config = $ config ?: ObjectManager:: getInstance ()-> get (Config::class) ;
52
53
}
53
54
54
55
/**
You can’t perform that action at this time.
0 commit comments