Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add latest post plugin with configurable limit #86

Merged
merged 13 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Classes/Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ public function listRecentPostsAction(): void
$this->view->assign('posts', $posts);
}

/**
* Show a number of latest posts.
*
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function listLatestPostsAction(): void
{
$maximumItems = (int) ($this->settings['lists']['posts']['numberOfLatestItems'] ?: 3);
$posts = $this->postRepository->findAllWithLimit($maximumItems);

$this->view->assign('posts', $posts);
}

/**
* @param int $year
* @param int $month
Expand Down
32 changes: 32 additions & 0 deletions Configuration/FlexForms/LatestPosts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>

benjaminkott marked this conversation as resolved.
Show resolved Hide resolved
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>
LLL:EXT:blog/Resources/Private/Language/locallang_db.xlf:display_flexform.sheet_general
benjaminkott marked this conversation as resolved.
Show resolved Hide resolved
</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.lists.posts.numberOfLatestItems>
<TCEforms>
<label>
LLL:EXT:blog/Resources/Private/Language/locallang_db.xlf:display_flexform.maximumDisplayedItems
benjaminkott marked this conversation as resolved.
Show resolved Hide resolved
</label>
<config>
<type>input</type>
<eval>int</eval>
</config>
</TCEforms>
</settings.lists.posts.numberOfLatestItems>
</el>
</ROOT>
</sDEF>

benjaminkott marked this conversation as resolved.
Show resolved Hide resolved
</sheets>
</T3DataStructure>
6 changes: 6 additions & 0 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['blog_posts'] = 'select_key';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['blog_metadata'] = 'recursive,select_key,pages';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['blog_sidebar'] = 'recursive,select_key,pages';

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['blog_latestposts'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'blog_latestposts',
'FILE:EXT:blog/Configuration/FlexForms/LatestPosts.xml'
);
2 changes: 2 additions & 0 deletions Configuration/TypoScript/Static/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ plugin {
posts {
# cat=blog/blog_120_lists; type=int+; label= LLL:EXT:blog/Resources/Private/Language/locallang.xlf:constantEditor.lists.posts.maximumDisplayedItems
maximumDisplayedItems = 0
# cat=blog/blog_120_lists; type=int+; label= LLL:EXT:blog/Resources/Private/Language/locallang.xlf:constantEditor.lists.posts.numberOfLatestItems
numberOfLatestItems = 3
# cat=blog/blog_120_lists; type=string; label= LLL:EXT:blog/Resources/Private/Language/locallang.xlf:constantEditor.lists.posts.dateFormat
dateFormat = %d.%m.%Y
}
Expand Down
1 change: 1 addition & 0 deletions Configuration/TypoScript/Static/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ plugin.tx_blog {
}
posts {
maximumDisplayedItems = {$plugin.tx_blog.settings.lists.posts.maximumDisplayedItems}
numberOfLatestItems = {$plugin.tx_blog.settings.lists.posts.numberOfLatestItems}
dateFormat = {$plugin.tx_blog.settings.lists.posts.dateFormat}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@
<trans-unit id="constantEditor.lists.posts.maximumDisplayedItems" xml:space="preserve">
<source>Maximum displayed items:Maximum number of posts to be displayed (0 = no limit).</source>
</trans-unit>
<trans-unit id="constantEditor.lists.posts.numberOfLatestItems" xml:space="preserve">
<source>Amount of items to show in overview of latest posts.</source>
</trans-unit>
<trans-unit id="constantEditor.lists.posts.dateFormat" xml:space="preserve">
<source>Date format:The format for the list items (default: %d.%m.%Y).</source>
</trans-unit>
Expand Down
13 changes: 13 additions & 0 deletions Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<trans-unit id="plugin.blog_posts.description" xml:space="preserve">
<source>Displays a list of blog posts ordered by date. All non-hidden, non-deleted and non-archived posts are shown in the list.</source>
</trans-unit>
<trans-unit id="plugin.blog_latestposts.title" xml:space="preserve">
<source>Blog: Latest posts</source>
</trans-unit>
<trans-unit id="plugin.blog_latestposts.description" xml:space="preserve">
<source>Displays a number of latest posts. You can specify the amount of items yourself.</source>
</trans-unit>
<trans-unit id="plugin.blog_category.title" xml:space="preserve">
<source>Blog: List by category</source>
</trans-unit>
Expand Down Expand Up @@ -245,6 +251,13 @@
<trans-unit id="sys_category.posts" xml:space="preserve">
<source>Posts</source>
</trans-unit>

<trans-unit id="display_flexform.sheet_general" xml:space="preserve">
<source>General</source>
</trans-unit>
<trans-unit id="display_flexform.maximumDisplayedItems" xml:space="preserve">
<source>Amount of items to show in overview of latest posts</source>
</trans-unit>
</body>
</file>
</xliff>
9 changes: 9 additions & 0 deletions Resources/Private/Templates/Post/ListLatestPosts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<f:layout name="Default"/>
<f:section name="Content">
<f:render partial="List" arguments="{_all}"/>
</f:section>
<f:section name="FooterAssets">
benjaminkott marked this conversation as resolved.
Show resolved Hide resolved
<f:if condition="{settings.comments.disqus._typoScriptNodeValue} === '1'">
<script id="dsq-count-scr" src="//{settings.comments.disqus.shortname}.disqus.com/count.js" async></script>
</f:if>
</f:section>
4 changes: 4 additions & 0 deletions Resources/Private/Templates/Post/ListLatestPosts.rss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<f:layout name="Default" />
<f:section name="Content">
<f:render partial="List" arguments="{_all}" />
</f:section>
7 changes: 7 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
'Post' => 'listRecentPosts',
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3G.AgencyPack.Blog',
'LatestPosts',
[
'Post' => 'listLatestPosts',
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3G.AgencyPack.Blog',
'Category',
Expand Down
6 changes: 6 additions & 0 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
'LLL:EXT:blog/Resources/Private/Language/locallang_db.xlf:plugin.blog_posts.title',
'plugin-blog-posts'
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'T3G.AgencyPack.Blog',
'LatestPosts',
'LLL:EXT:blog/Resources/Private/Language/locallang_db.xlf:plugin.blog_latestposts.title',
'plugin-blog-posts'
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'T3G.AgencyPack.Blog',
'Category',
Expand Down