File tree Expand file tree Collapse file tree 8 files changed +154
-20
lines changed Expand file tree Collapse file tree 8 files changed +154
-20
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,29 @@ protected function _prepareLayout()
35
35
return parent ::_prepareLayout ();
36
36
}
37
37
38
+ /**
39
+ * Prepare posts collection
40
+ *
41
+ * @return void
42
+ */
43
+ protected function _preparePostCollection ()
44
+ {
45
+ parent ::_preparePostCollection ();
46
+
47
+ $ displayMode = $ this ->_scopeConfig ->getValue (
48
+ \Magefan \Blog \Helper \Config::XML_PATH_HOMEPAGE_DISPLAY_MODE ,
49
+ ScopeInterface::SCOPE_STORE
50
+ );
51
+ /* If featured posts enabled */
52
+ if ($ displayMode == 1 ) {
53
+ $ postIds = $ this ->_scopeConfig ->getValue (
54
+ \Magefan \Blog \Helper \Config::XML_PATH_HOMEPAGE_FEATURED_POST_IDS ,
55
+ ScopeInterface::SCOPE_STORE
56
+ );
57
+ $ this ->_postCollection ->addPostsFilter ($ postIds );
58
+ }
59
+ }
60
+
38
61
/**
39
62
* Retrieve blog title
40
63
* @return string
Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ public function getGroupedChilds()
56
56
->setOrder ('position ' )
57
57
->getTreeOrderedArray ();
58
58
59
+ foreach ($ array as $ key => $ item ) {
60
+ $ maxDepth = $ this ->maxDepth ();
61
+ if ($ maxDepth > 0 && $ item ->getLevel () >= $ maxDepth ) {
62
+ unset($ array [$ key ]);
63
+ }
64
+ }
65
+
59
66
$ this ->setData ($ k , $ array );
60
67
}
61
68
@@ -86,4 +93,18 @@ public function getIdentities()
86
93
{
87
94
return [\Magento \Cms \Model \Block::CACHE_TAG . '_blog_categories_widget ' ];
88
95
}
96
+
97
+
98
+ /**
99
+ * Retrieve categories maximum depth
100
+ * @return int
101
+ */
102
+ public function maxDepth ()
103
+ {
104
+ $ maxDepth = $ this ->_scopeConfig ->getValue (
105
+ 'mfblog/sidebar/ ' .$ this ->_widgetKey .'/max_depth ' , ScopeInterface::SCOPE_STORE
106
+ );
107
+
108
+ return (int )$ maxDepth ;
109
+ }
89
110
}
Original file line number Diff line number Diff line change @@ -28,23 +28,8 @@ class Featured extends \Magefan\Blog\Block\Post\PostList\AbstractList
28
28
protected function _preparePostCollection ()
29
29
{
30
30
parent ::_preparePostCollection ();
31
-
32
- $ postIds = $ this ->getPostIdsConfigValue ();
33
- $ postIds = explode (', ' , $ postIds );
34
- foreach ($ postIds as $ key => $ id ) {
35
- $ id = trim ($ id );
36
- if (!$ id ) {
37
- unset($ postIds [$ key ]);
38
- }
39
- }
40
-
41
- if (!count ($ postIds )) {
42
- $ postIds = [0 ];
43
- }
44
-
45
- $ this ->_postCollection ->addFieldToFilter (
46
- 'post_id ' ,
47
- ['in ' => $ postIds ]
31
+ $ this ->_postCollection ->addPostsFilter (
32
+ $ this ->getPostIdsConfigValue ()
48
33
);
49
34
}
50
35
Original file line number Diff line number Diff line change @@ -29,6 +29,16 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper
29
29
*/
30
30
const XML_PATH_TOP_MENU_SHOW_ITEM = 'mfblog/top_menu/show_item ' ;
31
31
32
+ /**
33
+ * Blog homepage display mode
34
+ */
35
+ const XML_PATH_HOMEPAGE_DISPLAY_MODE = 'mfblog/index_page/display_mode ' ;
36
+
37
+ /**
38
+ * Blog homepage featured post ids
39
+ */
40
+ const XML_PATH_HOMEPAGE_FEATURED_POST_IDS = 'mfblog/index_page/post_ids ' ;
41
+
32
42
/**
33
43
* Top menu item text config path
34
44
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2015-17 Magefan ([email protected] ). All rights reserved.
4
+ * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5
+ *
6
+ * Glory to Ukraine! Glory to the heroes!
7
+ */
8
+
9
+ namespace Magefan \Blog \Model \Config \Source ;
10
+
11
+ /**
12
+ * Comment statuses
13
+ */
14
+ class DisplayMode implements \Magento \Framework \Option \ArrayInterface
15
+ {
16
+ /**
17
+ * @const string
18
+ */
19
+ const PENDING = 0 ;
20
+
21
+ /**
22
+ * @const int
23
+ */
24
+ const APPROVED = 1 ;
25
+
26
+ /**
27
+ * Options int
28
+ *
29
+ * @return array
30
+ */
31
+ public function toOptionArray ()
32
+ {
33
+ return [
34
+ ['value ' => self ::PENDING , 'label ' => __ ('Recent Blog Posts ' )],
35
+ ['value ' => self ::APPROVED , 'label ' => __ ('Featured Blog Posts ' )],
36
+ ];
37
+ }
38
+
39
+ /**
40
+ * Get options in "key-value" format
41
+ *
42
+ * @return array
43
+ */
44
+ public function toArray ()
45
+ {
46
+ $ array = [];
47
+ foreach ($ this ->toOptionArray () as $ item ) {
48
+ $ array [$ item ['value ' ]] = $ item ['label ' ];
49
+ }
50
+ return $ array ;
51
+ }
52
+ }
Original file line number Diff line number Diff line change @@ -131,6 +131,33 @@ public function addStoreFilter($store, $withAdmin = true)
131
131
return $ this ;
132
132
}
133
133
134
+ /**
135
+ * Add posts filter to collection
136
+ * @param array|int|string $category
137
+ * @return $this
138
+ */
139
+ public function addPostsFilter ($ postIds )
140
+ {
141
+ if (!is_array ($ postIds )) {
142
+ $ postIds = explode (', ' , $ postIds );
143
+ foreach ($ postIds as $ key => $ id ) {
144
+ $ id = trim ($ id );
145
+ if (!$ id ) {
146
+ unset($ postIds [$ key ]);
147
+ }
148
+ }
149
+ }
150
+
151
+ if (!count ($ postIds )) {
152
+ $ postIds = [0 ];
153
+ }
154
+
155
+ $ this ->addFieldToFilter (
156
+ 'post_id ' ,
157
+ ['in ' => $ postIds ]
158
+ );
159
+ }
160
+
134
161
/**
135
162
* Add category filter to collection
136
163
* @param array|int|\Magefan\Blog\Model\Category $category
Original file line number Diff line number Diff line change 34
34
<field id =" title" translate =" label comment" type =" text" sortOrder =" 10" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
35
35
<label >Title</label >
36
36
</field >
37
- <field id =" meta_keywords" translate =" label comment" type =" textarea" sortOrder =" 20" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
37
+ <field id =" display_mode" translate =" label comment" type =" select" sortOrder =" 20" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
38
+ <label >Display Mode</label >
39
+ <source_model >Magefan\Blog\Model\Config\Source\DisplayMode</source_model >
40
+ </field >
41
+ <field id =" post_ids" translate =" label comment" type =" text" sortOrder =" 30" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
42
+ <label >Post IDs</label >
43
+ <depends >
44
+ <field id =" display_mode" >1</field >
45
+ </depends >
46
+ <comment >Please indicate post IDs (separated by comma) you want to display.</comment >
47
+ </field >
48
+ <field id =" meta_keywords" translate =" label comment" type =" textarea" sortOrder =" 40" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
38
49
<label >Meta Keywords</label >
39
50
</field >
40
- <field id =" meta_description" translate =" label comment" type =" textarea" sortOrder =" 30 " showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
51
+ <field id =" meta_description" translate =" label comment" type =" textarea" sortOrder =" 50 " showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
41
52
<label >Meta Description</label >
42
53
</field >
43
54
</group >
207
218
<label >Display Number Of Posts</label >
208
219
<source_model >Magento\Config\Model\Config\Source\Yesno</source_model >
209
220
</field >
210
- <field id =" sort_order" translate =" label comment" type =" text" sortOrder =" 20" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
221
+ <field id =" max_depth" type =" text" translate =" label" sortOrder =" 20" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
222
+ <label >Maximal Depth</label >
223
+ </field >
224
+ <field id =" sort_order" translate =" label comment" type =" text" sortOrder =" 30" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
211
225
<label >Sort Order</label >
212
226
</field >
213
227
</group >
Original file line number Diff line number Diff line change 15
15
</general >
16
16
<index_page >
17
17
<title >Blog</title >
18
+ <display_mode >0></display_mode >
18
19
</index_page >
19
20
<post_view >
20
21
<related_posts >
53
54
<enabled >1</enabled >
54
55
<show_posts_count >1</show_posts_count >
55
56
<sort_order >20</sort_order >
57
+ <max_depth >2</max_depth >
56
58
</categories >
57
59
<recent_posts >
58
60
<enabled >1</enabled >
You can’t perform that action at this time.
0 commit comments