Created
August 1, 2019 10:29
-
-
Save pquerner/f41171d2091b4a7bce11c4604aba0e44 to your computer and use it in GitHub Desktop.
RouteEnhancers in Searchresult for ext:news (ext:indexed_search)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') || die(); | |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\IndexedSearch\Controller\SearchController::class] = array( | |
'className' => \CuD\EntdeckenBase\Controller\Extensions\Indexedsearch\SearchController::class | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace CuD\EntdeckenBase\Controller\Extensions\Indexedsearch; | |
use CuD\CudNewsauthors\Domain\Model\News; | |
use GeorgRinger\News\Domain\Repository\NewsRepository; | |
use TYPO3\CMS\Core\Utility\MathUtility; | |
class SearchController extends \TYPO3\CMS\IndexedSearch\Controller\SearchController | |
{ | |
const EXT_NEWS_ARRAY_KEY = 'tx_news_pi1'; | |
/** | |
* Fetches news object of ext:news, if search record is a news | |
* This is done because RouteEnhancers does not work out of the box, because a "ugly" a href is | |
* generated in \TYPO3\CMS\IndexedSearch\Controller\SearchController by default. | |
* | |
* | |
* @param array $row | |
* @param int $headerOnly | |
* | |
* @return array|void | |
*/ | |
protected function compileSingleResultRow($row, $headerOnly = 0) | |
{ | |
$resultData = parent::compileSingleResultRow($row, $headerOnly); | |
if (isset($resultData['static_page_arguments'])) { | |
$pageArguments = json_decode($resultData['static_page_arguments'], TRUE); | |
if (!empty($pageArguments) && isset($pageArguments[self::EXT_NEWS_ARRAY_KEY]) | |
&& $pageArguments[self::EXT_NEWS_ARRAY_KEY]['news'] | |
&& MathUtility::canBeInterpretedAsInteger($pageArguments[self::EXT_NEWS_ARRAY_KEY]['news']) | |
) { | |
$newsUid = $pageArguments[self::EXT_NEWS_ARRAY_KEY]['news']; | |
/** @var NewsRepository $newsRepository */ | |
$newsRepository = $this->objectManager->get(NewsRepository::class); | |
/** @var News $article */ | |
$article = $newsRepository->findByUid($newsUid); | |
$resultData['__newsArticle'] = $article; | |
$resultData['__isNewsArticle'] = 1; | |
} | |
} | |
return $resultData; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" | |
xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers" | |
data-namespace-typo3-fluid="true"> | |
<div class="media"> | |
<div class="media-body"> | |
<h4 class="media-heading"> | |
<f:if condition="{settings.displayResultNumber}"> | |
<span class="tx-indexedsearch-result-number">{row.result_number}</span> | |
</f:if> | |
<f:if condition="{row.__isNewsArticle}"> | |
<f:then> | |
<n:link newsItem="{row.__newsArticle}" title="{row.__newsArticle.title}"> | |
<span itemprop="headline">{row.__newsArticle.title}</span> | |
</n:link> | |
</f:then> | |
<f:else> | |
<f:format.raw>{row.title}</f:format.raw> | |
</f:else> | |
</f:if> | |
<span>{row.rating}</span> | |
</h4> | |
<f:if condition="{row.headerOnly} == 0"> | |
<p> | |
<f:format.crop maxCharacters="{settings.results.summaryCropAfter}">{row.item_description} | |
</f:format.crop> | |
</p> | |
<ul class="list-inline"> | |
<li><strong> | |
<f:translate key="result.size"/> | |
</strong> {row.size} | |
</li> | |
<li><strong> | |
<f:translate key="result.created"/> | |
</strong> | |
<f:format.date>@{row.created}</f:format.date> | |
</li> | |
<li><strong> | |
<f:translate key="result.modified"/> | |
</strong> | |
<f:format.date>@{row.modified}</f:format.date> | |
</li> | |
<li><strong> | |
<f:translate key="result.path"/> | |
</strong> | |
<f:format.raw>{row.path}</f:format.raw> | |
</li> | |
</ul> | |
</f:if> | |
<f:if condition="{row.subresults}"> | |
<f:for each="{row.subresults.items}" as="subrow"> | |
<f:render partial="Searchresult" arguments="{row: subrow}"/> | |
</f:for> | |
</f:if> | |
</div> | |
</div> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment