16
16
*/
17
17
class PageBlockHtmlTopmenuBethtmlBeforeObserver implements ObserverInterface
18
18
{
19
+ /**
20
+ * Show top menu item config path
21
+ */
22
+ const XML_PATH_TOP_MENU_SHOW_ITEM = 'mfblog/top_menu/show_item ' ;
23
+
24
+ /**
25
+ * Top menu item text config path
26
+ */
27
+ const XML_PATH_TOP_MENU_ITEM_TEXT = 'mfblog/top_menu/item_text ' ;
28
+
19
29
/**
20
30
* @var \Magefan\Blog\Model\Url
21
31
*/
22
32
protected $ _url ;
23
33
34
+ /**
35
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
36
+ */
37
+ protected $ _scopeConfig ;
38
+
24
39
/**
25
40
* @param \Magefan\Blog\Model\Url $url
26
41
*/
27
42
public function __construct (
28
- \Magefan \Blog \Model \Url $ url
43
+ \Magefan \Blog \Model \Url $ url ,
44
+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig
29
45
) {
46
+ $ this ->_scopeConfig = $ scopeConfig ;
30
47
$ this ->_url = $ url ;
31
48
}
32
49
@@ -39,19 +56,22 @@ public function __construct(
39
56
*/
40
57
public function execute (\Magento \Framework \Event \Observer $ observer )
41
58
{
59
+ if (!$ this ->_scopeConfig ->isSetFlag (static ::XML_PATH_TOP_MENU_SHOW_ITEM , \Magento \Store \Model \ScopeInterface::SCOPE_STORE )) {
60
+ return ;
61
+ }
62
+
42
63
/** @var \Magento\Framework\Data\Tree\Node $menu */
43
64
$ menu = $ observer ->getMenu ();
44
65
$ block = $ observer ->getBlock ();
45
66
46
67
$ tree = $ menu ->getTree ();
47
68
$ data = [
48
- 'name ' => __ ( ' Blog ' ),
69
+ 'name ' => $ this -> _scopeConfig -> getValue ( static :: XML_PATH_TOP_MENU_ITEM_TEXT , \ Magento \ Store \ Model \ScopeInterface:: SCOPE_STORE ),
49
70
'id ' => 'magefan-blog ' ,
50
71
'url ' => $ this ->_url ->getBaseUrl (),
51
72
'is_active ' => ($ block ->getRequest ()->getModuleName () == 'blog ' ),
52
73
];
53
74
$ node = new Node ($ data , 'id ' , $ tree , $ menu );
54
75
$ menu ->addChild ($ node );
55
- return $ this ;
56
76
}
57
77
}
0 commit comments