From ec1b1a909e91b39a9dd48b94c1e85335ab5a6062 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid <kevin.ditscheid@sgalinski.de> Date: Tue, 22 Mar 2022 10:46:59 +0100 Subject: [PATCH] [TASK] Cleanup code and use ViewHelper in SIngleView --- Classes/Domain/Model/News.php | 24 --------- Classes/Domain/Repository/NewsRepository.php | 1 - .../TypoScript/Frontend/constants.typoscript | 6 --- .../TypoScript/Frontend/setup.typoscript | 6 --- .../Templates/SingleView/SingleView.html | 49 +++++++++++++------ 5 files changed, 34 insertions(+), 52 deletions(-) diff --git a/Classes/Domain/Model/News.php b/Classes/Domain/Model/News.php index fd90345..d273fa1 100644 --- a/Classes/Domain/Model/News.php +++ b/Classes/Domain/Model/News.php @@ -26,12 +26,8 @@ namespace SGalinski\SgNews\Domain\Model; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use SGalinski\SgNews\Domain\Repository\NewsRepository; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy; use TYPO3\CMS\Extbase\Persistence\ObjectStorage; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; -use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; /** * News @@ -101,20 +97,6 @@ class News extends CategoryAndNews { */ protected $contentFromAnotherPage = 0; - /** - * @var ConfigurationManager - */ - protected $configurationManager; - - /** - * Inject the configuration manager - * - * @param ConfigurationManager $configurationManager - */ - public function injectConfigurationManager(ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; - } - /** * Constructor */ @@ -200,12 +182,6 @@ class News extends CategoryAndNews { $this->relatedNews->_loadRealInstance(); } - $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS); - if ($settings['automaticRelatedNews'] && !$this->_isNew() && $this->relatedNews->count() === 0) { - $newsRepository = GeneralUtility::makeInstance(NewsRepository::class); - $this->relatedNews = $newsRepository->findRelated($this, $settings['limitRelatedNews']); - } - return $this->relatedNews; } diff --git a/Classes/Domain/Repository/NewsRepository.php b/Classes/Domain/Repository/NewsRepository.php index e09d74e..d12d51a 100644 --- a/Classes/Domain/Repository/NewsRepository.php +++ b/Classes/Domain/Repository/NewsRepository.php @@ -26,7 +26,6 @@ namespace SGalinski\SgNews\Domain\Repository; * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -use SGalinski\SgNews\Domain\Model\Author; use SGalinski\SgNews\Domain\Model\News; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\ConnectionPool; diff --git a/Configuration/TypoScript/Frontend/constants.typoscript b/Configuration/TypoScript/Frontend/constants.typoscript index 6da22e8..34a9c4d 100644 --- a/Configuration/TypoScript/Frontend/constants.typoscript +++ b/Configuration/TypoScript/Frontend/constants.typoscript @@ -19,11 +19,5 @@ plugin.tx_sgnews { # sort direction (DESC / ASC) sortDirection = DESC - - # Enable fetching of related news by tag or category, if related news are not set manually - automaticRelatedNews = 1 - - # Set a limit for fetched related news (for no limit, set to 0) - limitRelatedNews = 5 } } diff --git a/Configuration/TypoScript/Frontend/setup.typoscript b/Configuration/TypoScript/Frontend/setup.typoscript index 1d41c08..9a52fd4 100644 --- a/Configuration/TypoScript/Frontend/setup.typoscript +++ b/Configuration/TypoScript/Frontend/setup.typoscript @@ -109,12 +109,6 @@ plugin.tx_sgnews { # The logo value for the structured data implementation (see single view template) publisherLogo = - - # Enable fetching of related news by tag or category, if related news are not set manually - automaticRelatedNews = {$plugin.tx_sgnews.settings.automaticRelatedNews} - - # Set a limit for fetched related news (for no limit, set to 0) - limitRelatedNews = {$plugin.tx_sgnews.settings.limitRelatedNews} } features { diff --git a/Resources/Private/Templates/SingleView/SingleView.html b/Resources/Private/Templates/SingleView/SingleView.html index e41e216..5d2e817 100644 --- a/Resources/Private/Templates/SingleView/SingleView.html +++ b/Resources/Private/Templates/SingleView/SingleView.html @@ -179,21 +179,40 @@ </div> <f:if condition="{newsMetaData.news.relatedNews}"> - <div class="tx-sgnews-single-related"> - <h3> - <f:translate key="frontend.singleview.relatedArticles" /> - </h3> - - <ul> - <f:for each="{newsMetaData.news.relatedNews}" as="relatedNewsEntry"> - <li> - <a href="{f:uri.page(pageUid: '{relatedNewsEntry.uid}')}"> - {relatedNewsEntry.subtitleWithFallbackToTitle} - </a> - </li> - </f:for> - </ul> - </div> + <f:then> + <div class="tx-sgnews-single-related"> + <h3> + <f:translate key="frontend.singleview.relatedArticles" /> + </h3> + + <ul> + <f:for each="{newsMetaData.news.relatedNews}" as="relatedNewsEntry"> + <li> + <a href="{f:uri.page(pageUid: '{relatedNewsEntry.uid}')}"> + {relatedNewsEntry.subtitleWithFallbackToTitle} + </a> + </li> + </f:for> + </ul> + </div> + </f:then> + <f:else> + <div class="tx-sgnews-single-related"> + <h3> + <f:translate key="frontend.singleview.relatedArticles" /> + </h3> + + <ul> + <sg:related news="{newsMetaData.news}" limit="5" as="relatedNewsEntry"> + <li> + <a href="{f:uri.page(pageUid: '{relatedNewsEntry.uid}')}"> + {relatedNewsEntry.subtitleWithFallbackToTitle} + </a> + </li> + </sg:related> + </ul> + </div> + </f:else> </f:if> </div> </div> -- GitLab