Skip to content

Commit b0bcdf1

Browse files
Philipp Kuhlmayo-ba
authored andcommitted
[BUGFIX] Add specific file link generator for ext:styleguide
TCA-Examples inside EXT:styleguide provide generated example data to demonstrate functionality. Up until now, no specified generator option could be applied to fields defined as `type=link` and `allowedFileExtensions` applied, meaning the link for a file should be created. This was a simple web page link until now, which did not reflect the wanted behaviour. A new generator is now introduced, providing links to the example files ext:styleguide ships. Resolves: #104224 Releases: main, 13.4 Change-Id: I304f9c20501068e118464cf614f0da9da310efd9 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84932 Tested-by: Garvin Hicking <gh@faktor-e.de> Tested-by: Oliver Bartsch <bo@cedev.de> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Garvin Hicking <gh@faktor-e.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Sebastian Iffland <sebastian.iffland@fullhaus.de>
1 parent 67d1b62 commit b0bcdf1

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
namespace TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator;
19+
20+
use TYPO3\CMS\Core\LinkHandling\FileLinkHandler;
21+
use TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface;
22+
use TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder;
23+
24+
/**
25+
* Generate data for type=link fields, where allowed type is file only
26+
*
27+
* @internal
28+
*/
29+
final class TypeLinkFile extends AbstractFieldGenerator implements FieldGeneratorInterface
30+
{
31+
protected array $matchArray = [
32+
'fieldConfig' => [
33+
'config' => [
34+
'type' => 'link',
35+
'allowedTypes' => ['file'],
36+
],
37+
],
38+
];
39+
40+
public function __construct(
41+
private readonly RecordFinder $recordFinder,
42+
private readonly FileLinkHandler $fileLinkHandler
43+
) {}
44+
45+
public function generate(array $data): string
46+
{
47+
$demoImages = $this->recordFinder->findDemoFileObjects();
48+
$image = next($demoImages);
49+
return $this->fileLinkHandler->asString(['file' => $image]);
50+
}
51+
}

typo3/sysext/styleguide/Configuration/Services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ services:
6363
# General type=datetime generator
6464
- '@TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeDatetime'
6565

66+
# Specific type=link generator
67+
- '@TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeLinkFile'
68+
6669
# General type=link generator
6770
- '@TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeLink'
6871

typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@
531531
],
532532
'link_2' => [
533533
'label' => 'link_2',
534-
'description' => 'type=link allowedTypes=file allowedOptions=allowedFileExtensions=png',
534+
'description' => 'type=link allowedTypes=file allowedOptions=allowedFileExtensions=jpg,png',
535535
'config' => [
536536
'type' => 'link',
537537
'allowedTypes' => ['file'],
538538
'appearance' => [
539-
'allowedFileExtensions' => ['png'],
539+
'allowedFileExtensions' => ['jpg', 'png'],
540540
],
541541
],
542542
],

0 commit comments

Comments
 (0)