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

[BUGFIX] Fix backend preview with multiple categories #459

Merged
merged 10 commits into from
Feb 14, 2024
10 changes: 10 additions & 0 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,16 @@ public function getImages(): array
return $references;
}

public function getFirstImage(): ?FileReference
{
$this->images->rewind();
if ($this->images->count()) {
return $this->images->current();
}

return null;
}

public function setImages(ObjectStorage $images): void
{
$this->images = $images;
Expand Down
63 changes: 63 additions & 0 deletions Classes/ViewHelpers/SettingsFormatViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/*
* This file is part of the package jweiland/events2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

namespace JWeiland\Events2\ViewHelpers;

use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* SettingsFormatViewHelper ViewHelper
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
*
* Explodes a string by $glue.
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
*/
class SettingsFormatViewHelper extends AbstractViewHelper
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
{
use CompileWithRenderStatic;

public function initializeArguments(): void
{
$this->registerArgument('content', 'string', 'String to be formatted by limit if set');
$this->registerArgument(
'glue',
'string',
'String "glue" that separates values. If you need a constant (like PHP_EOL)',
false,
','
);
$this->registerArgument(
'limit',
'int',
'If limit is set and positive, only the first few values are combined into a new ' .
'comma-separated string and appended with "...". If the limit parameter is negative, ' .
'only the last few values are combined into a new comma-separated string with APPENDED?!!! "...". ' .
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
'If the limit parameter is zero, it is treated as 1, so only ONE element is shown with APPENDED "...".',
false,
10
);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
$content = $arguments['content'];
$glue = $arguments['glue'];
$limit = $arguments['limit'] ?? MathUtility::forceIntegerInRange($arguments['limit'], 1);
$explodedStringArray = explode($glue, (string)$content);
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
$output = array_slice($explodedStringArray, 0, $limit);

return implode(', ', $output) . '", ...';
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 8 additions & 1 deletion Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
ChangeLog
=========

Version 9.0.2
=============

* [BUGFIX] fixed broken backend template preview if more than 10 categories
selected
* [TASK] Added GetFirstImage function in Event Model to avoid iteration in Fluid

Version 9.0.1
=============

* Bugfix: Repair scheduler task for re-generate day records
* Bugfix: Repair scheduler task for re-generate day records
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved

Version 9.0.0
=============
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[general]

project = jweiland-net/events2
version = 9.0.1
version = 9.0.2
release = 9.0
copyright = by jweiland.net

Expand Down
30 changes: 13 additions & 17 deletions Resources/Private/Partials/Event/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,19 @@ <h5 class="media-heading">

<f:section name="FirstImage">
<f:if condition="{event.images -> f:count()}">
<f:for each="{event.images}" as="image" iteration="iterator">
<f:if condition="{iterator.isFirst}">
<figure>
<f:image
image="{image}"
alt="{event.title}"
title="{event.title}"
width="{settings.list.image.width}"
height="{settings.list.image.height}"
minWidth="{settings.list.image.minWidth}"
maxWidth="{settings.list.image.maxWidth}"
minHeight="{settings.list.image.minHeight}"
maxHeight="{settings.list.image.maxHeight}"
/>
</figure>
</f:if>
</f:for>
<figure>
<f:image
image="{event.firstImage}"
alt="{event.title}"
title="{event.title}"
width="{settings.list.image.width}"
height="{settings.list.image.height}"
minWidth="{settings.list.image.minWidth}"
maxWidth="{settings.list.image.maxWidth}"
minHeight="{settings.list.image.minHeight}"
maxHeight="{settings.list.image.maxHeight}"
/>
</figure>
</f:if>
</f:section>
</html>
3 changes: 2 additions & 1 deletion Resources/Private/Templates/PluginPreview/Events.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:e2="http://typo3.org/ns/JWeiland/Events2/ViewHelpers"
data-namespace-typo3-fluid="true">

<h4>Events2</h4>
Expand Down Expand Up @@ -96,7 +97,7 @@ <h4>Events2</h4>
<f:if condition="{categories}">
<tr>
<td><strong>Categories</strong></td>
<td>{categories}</td>
<td>{e2:settingsFormat(content: '{categories}', glue: ',')}</td>
hojalatheef marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</f:if>
</f:section>
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'author_email' => 'projects@jweiland.net',
'author_company' => 'jweiland.net',
'state' => 'stable',
'version' => '9.0.1',
'version' => '9.0.2',
'constraints' => [
'depends' => [
'typo3' => '12.4.8-12.4.99',
Expand Down
Loading