Skip to content

Commit 192e6c3

Browse files
authored
Merge pull request #121 from magefan/185-include-in-recent
Added ability to skip posts from displaying on blog homepage, recent sidebar block, recent widget
2 parents 4b57492 + 4e1015f commit 192e6c3

File tree

7 files changed

+68
-9
lines changed

7 files changed

+68
-9
lines changed

Block/Index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ protected function _preparePostCollection()
4848
\Magefan\Blog\Helper\Config::XML_PATH_HOMEPAGE_DISPLAY_MODE,
4949
ScopeInterface::SCOPE_STORE
5050
);
51+
5152
/* If featured posts enabled */
5253
if ($displayMode == 1) {
5354
$postIds = $this->_scopeConfig->getValue(
5455
\Magefan\Blog\Helper\Config::XML_PATH_HOMEPAGE_FEATURED_POST_IDS,
5556
ScopeInterface::SCOPE_STORE
5657
);
5758
$this->_postCollection->addPostsFilter($postIds);
59+
} else {
60+
$this->_postCollection->addRecentFilter();
5861
}
5962
}
6063

Block/Sidebar/Recent.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ public function _construct()
3434
return parent::_construct();
3535
}
3636

37+
/*
38+
* Prepare posts collection
39+
*
40+
* @return void
41+
*/
42+
protected function _preparePostCollection()
43+
{
44+
parent::_preparePostCollection();
45+
$this->_postCollection->addRecentFilter();
46+
}
47+
3748
/**
3849
* Retrieve block identities
3950
* @return array

Block/Widget/Recent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ protected function _preparePostCollection()
9191

9292
parent::_preparePostCollection();
9393

94+
$this->_postCollection->addRecentFilter();
9495
if ($category = $this->getCategory()) {
9596
$this->_postCollection->addCategoryFilter($category);
9697
}

Model/ResourceModel/Post/Collection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,16 @@ public function addStoreFilter($store, $withAdmin = true)
130130
}
131131
return $this;
132132
}
133-
133+
134+
/**
135+
* Add "include in recent" filter to collection
136+
* @return $this
137+
*/
138+
public function addRecentFilter()
139+
{
140+
return $this->addFieldToFilter('include_in_recent', 1);
141+
}
142+
134143
/**
135144
* Add posts filter to collection
136145
* @param array|int|string $category

Setup/UpgradeSchema.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
6363
}
6464

6565
if (version_compare($version, '2.2.0') < 0) {
66-
/* Add author field to posts tabel */
66+
/* Add author field to posts table */
6767
$connection->addColumn(
6868
$setup->getTable('magefan_blog_post'),
6969
'author_id',
@@ -84,7 +84,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
8484

8585

8686
if (version_compare($version, '2.2.5') < 0) {
87-
/* Add layout field to posts and category tabels */
87+
/* Add layout field to posts and category table */
8888
foreach (['magefan_blog_post', 'magefan_blog_category'] as $table) {
8989
$table = $setup->getTable($table);
9090
$connection->addColumn(
@@ -165,7 +165,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
165165
}
166166

167167
if (version_compare($version, '2.3.0') < 0) {
168-
/* Add meta title field to posts tabel */
168+
/* Add meta title field to posts table */
169169
$connection->addColumn(
170170
$setup->getTable('magefan_blog_post'),
171171
'meta_title',
@@ -178,7 +178,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
178178
]
179179
);
180180

181-
/* Add og tags fields to post tabel */
181+
/* Add og tags fields to post table */
182182
foreach (['type', 'img', 'description', 'title'] as $type) {
183183
$connection->addColumn(
184184
$setup->getTable('magefan_blog_post'),
@@ -193,7 +193,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
193193
);
194194
}
195195

196-
/* Add meta title field to category tabel */
196+
/* Add meta title field to category table */
197197
$connection->addColumn(
198198
$setup->getTable('magefan_blog_category'),
199199
'meta_title',
@@ -452,7 +452,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
452452
}
453453

454454
if (version_compare($version, '2.6.2') < 0) {
455-
/* Add include in menu field into categories tabel */
455+
/* Add include in menu field into categories table */
456456
$connection->addColumn(
457457
$setup->getTable('magefan_blog_category'),
458458
'include_in_menu',
@@ -473,7 +473,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
473473
}
474474

475475
if (version_compare($version, '2.6.3') < 0) {
476-
/* Add display mode field into category tabel */
476+
/* Add display mode field into category table */
477477
$connection->addColumn(
478478
$setup->getTable('magefan_blog_category'),
479479
'display_mode',
@@ -488,6 +488,23 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
488488
);
489489
}
490490

491+
492+
if (version_compare($version, '2.6.3.1') < 0) {
493+
/* Add include in recent posts into post table */
494+
$connection->addColumn(
495+
$setup->getTable('magefan_blog_post'),
496+
'include_in_recent',
497+
[
498+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
499+
null,
500+
'nullable' => false,
501+
'default' => '1',
502+
'comment' => 'Include in Recent Posts',
503+
'after' => 'is_active'
504+
]
505+
);
506+
}
507+
491508
$setup->endSetup();
492509
}
493510
}

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
-->
1010
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
11-
<module name="Magefan_Blog" setup_version="2.6.3">
11+
<module name="Magefan_Blog" setup_version="2.6.3.1">
1212
<sequence>
1313
<module name="Magento_Cms"/>
1414
<module name="Magento_Catalog"/>

view/adminhtml/ui_component/blog_post_form.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@
325325
</argument>
326326
</container>
327327
</container>
328+
<field name="include_in_recent">
329+
<argument name="data" xsi:type="array">
330+
<item name="config" xsi:type="array">
331+
<item name="dataType" xsi:type="string">boolean</item>
332+
<item name="label" xsi:type="string" translate="true">Include in Recent Posts</item>
333+
<item name="formElement" xsi:type="string">checkbox</item>
334+
<item name="prefer" xsi:type="string">toggle</item>
335+
<item name="source" xsi:type="string">post</item>
336+
<item name="sortOrder" xsi:type="number">60</item>
337+
<item name="dataScope" xsi:type="string">include_in_recent</item>
338+
<item name="valueMap" xsi:type="array">
339+
<item name="true" xsi:type="number">1</item>
340+
<item name="false" xsi:type="number">0</item>
341+
</item>
342+
<item name="default" xsi:type="number">1</item>
343+
</item>
344+
</argument>
345+
</field>
328346
</fieldset>
329347
<!-- Revert htmlContent to enable post gallery images on Magento 2.2.2
330348
<htmlContent name="gallery" sortOrder="22">

0 commit comments

Comments
 (0)