Skip to content
Snippets Groups Projects
Verified Commit 222e6f28 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Add the possibility to reuse the Teaser partial

parent 6b81aec7
No related branches found
No related tags found
1 merge request!44[BUGFIX] Fix bugs with fetching the related news
......@@ -26,6 +26,9 @@ namespace SGalinski\SgNews\Domain\Model;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgNews\Domain\Repository\CategoryRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
......@@ -102,6 +105,16 @@ class News extends CategoryAndNews {
*/
protected $enableComments = TRUE;
/**
* @var Category
*/
protected $categoryCache = NULL;
/**
* @var FileReference
*/
protected $teaserImageCache = NULL;
/**
* Constructor
*/
......@@ -402,4 +415,64 @@ class News extends CategoryAndNews {
public function setEnableComments(bool $enableComments): void {
$this->enableComments = $enableComments;
}
/**
* Get the assigned category
*
* @return Category
*/
public function getCategory(): Category {
if ($this->categoryCache instanceof Category) {
return $this->categoryCache;
}
return $this->categoryCache = GeneralUtility::makeInstance(CategoryRepository::class)
->findByUid($this->pid);
}
/**
* Get the teaser image object
*
* @return FileReference|null
*/
public function getTeaserImageObject(): ?FileReference {
if ($this->teaserImageCache instanceof FileReference) {
return $this->teaserImageCache;
}
$teaserImage = $this->getTeaser1Image()->current();
if ($teaserImage instanceof FileReference) {
return $this->teaserImageCache = $teaserImage;
}
$teaserImage = $this->getCategory()->getTeaser1Image()->current();
if ($teaserImage instanceof FileReference) {
return $this->teaserImageCache = $teaserImage;
}
$teaserImage = $this->getTeaser2Image()->current();
if ($teaserImage instanceof FileReference) {
return $this->teaserImageCache = $teaserImage;
}
return NULL;
}
/**
* Get the teaser image public url
*
* @return string
*/
public function getTeaserImage() {
$teaserImage = $this->getTeaserImageObject();
if ($teaserImage === NULL) {
return '';
}
$originalResource = $teaserImage->getOriginalResource();
if ($originalResource === NULL) {
return '';
}
return $originalResource->getPublicUrl();
}
}
......@@ -221,6 +221,13 @@
iteration="iterator"
limit="5"
as="relatedNewsEntry">
<f:variable name="relatedNewsMetaData"
value="{
news: relatedNewsEntry,
teaserImage: relatedNewsEntry.teaserImage,
teaserImageObject: relatedNewsEntry.teaserImageObject,
category: relatedNewsEntry.category
}" />
<f:if condition="{iterator.isFirst}">
<div class="tx-sgnews-single-related">
<h3>
......@@ -229,10 +236,11 @@
<ul class="tx-sgnews-list tx-sgnews-overview">
</f:if>
<li class="col-md-4 col-sm-6 col-xs-12">
<f:render partial="TeaserRelated" arguments="{
news: relatedNewsEntry,
<f:render partial="Teaser" arguments="{
newsMetaData: relatedNewsMetaData,
headerTag: '<h2>',
closingHeaderTag: '</h2>'
closingHeaderTag: '</h2>',
showCategory: '1'
}" />
</li>
<f:if condition="{iterator.isLast}">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment