diff --git a/Classes/Domain/Model/Event.php b/Classes/Domain/Model/Event.php index ebaa53e1..7f4d3fae 100644 --- a/Classes/Domain/Model/Event.php +++ b/Classes/Domain/Model/Event.php @@ -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; diff --git a/Classes/ViewHelpers/CropStringViewHelper.php b/Classes/ViewHelpers/CropStringViewHelper.php new file mode 100644 index 00000000..1c2edb29 --- /dev/null +++ b/Classes/ViewHelpers/CropStringViewHelper.php @@ -0,0 +1,92 @@ + + * {namespace e2=JWeiland\Events2\ViewHelpers} + * + * + * + * In this example, the `cropString` ViewHelper will take the `contentSeperatedByCommas` string, split it by commas, + * and return the first 5 elements as a comma-separated string. If there are more than 5 elements, + * it will append "..." to the end of the string. + */ +class CropStringViewHelper extends AbstractViewHelper +{ + 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 the limit is higher than the given content (array of categories) count it will just return the comma ' . + 'seperated values. If the limit is set and positive, only the first few values are combined into a new ' . + 'comma-separated string, for example "75, 44, 62,...". If the limit parameter is negative, ' . + 'only the last few values are combined into a new comma-separated string, for example "..., 1, 56, 7". ' . + 'If the limit parameter is zero, it is treated as 1, so only ONE element is shown, for example "75".', + false, + 10 + ); + } + + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ): string { + $content = $arguments['content']; + $glue = $arguments['glue']; + $limit = (int)$arguments['limit']; + + $explodedStringArray = explode($glue, (string)$content); + + // return the imploded content with glue if limit is higher than the given content count + if ($limit > count($explodedStringArray)) { + return implode($glue . ' ', $explodedStringArray); + } + + // return the imploded content with glue if limit is set and positive with limit given or default 10 and post fix the content with ",..." + if ($limit > 0) { + $output = array_slice($explodedStringArray, 0, $limit); + return implode($glue . ' ', $output) . ',...'; + } + + // return the imploded content with glue if limit is set and negative with limit given or default 10 and pre fix the content with "...," + if ($limit < 0) { + $output = array_slice($explodedStringArray, $limit); + return '...,' . implode($glue . ' ', $output); + } + + // return the first element of the exploded content if limit is set to 0 + if ($limit === 0) { + return $explodedStringArray[0]; + } + } +} diff --git a/Documentation/ChangeLog/Index.rst b/Documentation/ChangeLog/Index.rst index 2de98009..a7e8ce05 100644 --- a/Documentation/ChangeLog/Index.rst +++ b/Documentation/ChangeLog/Index.rst @@ -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 Version 9.0.0 ============= diff --git a/Documentation/Settings.cfg b/Documentation/Settings.cfg index fb0b682d..1410bb09 100644 --- a/Documentation/Settings.cfg +++ b/Documentation/Settings.cfg @@ -4,7 +4,7 @@ [general] project = jweiland-net/events2 -version = 9.0.1 +version = 9.0.2 release = 9.0 copyright = by jweiland.net diff --git a/Resources/Private/Partials/Event/List.html b/Resources/Private/Partials/Event/List.html index b200d409..6e1aafaf 100644 --- a/Resources/Private/Partials/Event/List.html +++ b/Resources/Private/Partials/Event/List.html @@ -85,23 +85,19 @@
- - -
- -
-
-
+
+ +
diff --git a/Resources/Private/Templates/PluginPreview/Events.html b/Resources/Private/Templates/PluginPreview/Events.html index 12504bf1..5b223d74 100644 --- a/Resources/Private/Templates/PluginPreview/Events.html +++ b/Resources/Private/Templates/PluginPreview/Events.html @@ -1,6 +1,7 @@

Events2

@@ -96,7 +97,7 @@

Events2

Categories - {categories} + {e2:cropString(content: categories, glue: ',')} diff --git a/ext_emconf.php b/ext_emconf.php index 78947001..13119241 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -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',