• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 12934324154

23 Jan 2025 05:06PM UTC coverage: 93.29% (-0.003%) from 93.293%
12934324154

push

github

NamelessCoder
[BUGFIX] Return a proper icon reference from FluidFileBased content definition

11 of 12 new or added lines in 1 file covered. (91.67%)

7035 of 7541 relevant lines covered (93.29%)

56.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.87
/Classes/Content/TypeDefinition/FluidFileBased/FluidFileBasedContentTypeDefinition.php
1
<?php
2
declare(strict_types=1);
3
namespace FluidTYPO3\Flux\Content\TypeDefinition\FluidFileBased;
4

5
/*
6
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.md file that was distributed with this source code.
10
 */
11

12
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
13
use FluidTYPO3\Flux\Form;
14
use FluidTYPO3\Flux\Provider\Provider;
15
use FluidTYPO3\Flux\Provider\ProviderResolver;
16
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18

19
/**
20
 * Fluid File-based Content Type Definition
21
 *
22
 * Class to hold the metadata required to operate a single
23
 * content type based on a Fluid template.
24
 */
25
class FluidFileBasedContentTypeDefinition implements FluidRenderingContentTypeDefinitionInterface
26
{
27
    protected string $extensionIdentity = '';
28
    protected string $basePath = '';
29
    protected string $relativeFilePath = '';
30
    protected string $providerClassName = Provider::class;
31

32
    /**
33
     * Constructs a Fluid file-based content type definition
34
     *
35
     * Can be used to construct definitions based on template files
36
     * which contain Flux form definitions and supports sub-folders
37
     * for template files by specifying $relativeFilePath as a path
38
     * inside a folder relative to the $basePath.
39
     *
40
     * @param string $extensionIdentity The VendorName.ExtensionName identity of the extension that contains the file
41
     * @param string $basePath Absolute path, or EXT:... path to location of template file
42
     * @param string $relativeFilePath Path of file relative to $basePath, without leading slash
43
     * @param string $providerClassName Class name of a Flux ProviderInterface implementation that handles the CType
44
     */
45
    public function __construct(
46
        string $extensionIdentity,
47
        string $basePath,
48
        string $relativeFilePath,
49
        string $providerClassName = Provider::class
50
    ) {
51
        $this->extensionIdentity = $extensionIdentity;
30✔
52
        $this->basePath = $basePath;
30✔
53
        $this->relativeFilePath = $relativeFilePath;
30✔
54
        $this->providerClassName = $providerClassName;
30✔
55
    }
56

57
    public function getForm(array $record = []): Form
58
    {
59
        $provider = $this->getProviderResolver()->resolvePrimaryConfigurationProvider(
12✔
60
            'tt_content',
12✔
61
            'pi_flexform',
12✔
62
            $record
12✔
63
        );
12✔
64
        /** @var Form $defaultForm */
65
        $defaultForm = Form::create();
12✔
66

67
        if ($provider === null) {
12✔
68
            return $defaultForm;
6✔
69
        }
70
        return $provider->getForm($record) ?? $defaultForm;
6✔
71
    }
72

73
    public function getGrid(array $record = []): Form\Container\Grid
74
    {
75
        $provider = $this->getProviderResolver()->resolvePrimaryConfigurationProvider(
12✔
76
            'tt_content',
12✔
77
            'pi_flexform',
12✔
78
            $record
12✔
79
        );
12✔
80
        if ($provider === null) {
12✔
81
            /** @var Form\Container\Grid $grid */
82
            $grid = Form\Container\Grid::create();
6✔
83
            return $grid;
6✔
84
        }
85
        return $provider->getGrid($record);
6✔
86
    }
87

88
    public static function fetchContentTypes(): iterable
89
    {
90
        return [];
6✔
91
    }
92

93
    public function getContentTypeName(): string
94
    {
95
        $path = pathinfo($this->relativeFilePath, PATHINFO_DIRNAME);
12✔
96
        $path = $path === '.' ? '' : $path . '_';
12✔
97
        $extensionSignature = str_replace('_', '', ExtensionNamingUtility::getExtensionKey($this->extensionIdentity));
12✔
98
        $contentReference = str_replace('/', '_', $path . pathinfo($this->relativeFilePath, PATHINFO_FILENAME));
12✔
99
        return $extensionSignature . '_' . strtolower($contentReference);
12✔
100
    }
101

102
    public function getIconReference(): string
103
    {
104
        $extensionKey = ExtensionNamingUtility::getExtensionKey($this->extensionIdentity);
6✔
105
        $contentType = $this->getContentTypeName();
6✔
106
        $files = [
6✔
107
            'EXT:' . $extensionKey . '/Resources/Public/Icons/Content/' . $contentType . '.svg',
6✔
108
            'EXT:' . $extensionKey . '/Resources/Public/Icons/Content/' . $contentType . '.png',
6✔
109
            'EXT:' . $extensionKey . '/Resources/Public/Icons/Content/' . $contentType . '.gif',
6✔
110
        ];
6✔
111

112
        foreach ($files as $potentialIconFile) {
6✔
113
            $absoluteFileName = GeneralUtility::getFileAbsFileName($potentialIconFile);
6✔
114
            if (file_exists($absoluteFileName)) {
6✔
NEW
115
                return $potentialIconFile;
×
116
            }
117
        }
118

119
        return 'EXT:flux/Resources/Public/Icons/Extension.svg';
6✔
120
    }
121

122
    public function getExtensionIdentity(): string
123
    {
124
        return $this->extensionIdentity;
12✔
125
    }
126

127
    public function getProviderClassName(): ?string
128
    {
129
        return $this->providerClassName;
6✔
130
    }
131

132
    public function isUsingTemplateFile(): bool
133
    {
134
        return true;
6✔
135
    }
136

137
    public function isUsingGeneratedTemplateSource(): bool
138
    {
139
        return false;
6✔
140
    }
141

142
    public function getTemplatePathAndFilename(): string
143
    {
144
        return $this->basePath . $this->relativeFilePath;
6✔
145
    }
146

147
    protected function getProviderResolver(): ProviderResolver
148
    {
149
        /** @var ProviderResolver $providerResolver */
150
        $providerResolver = GeneralUtility::makeInstance(ProviderResolver::class);
24✔
151
        return $providerResolver;
24✔
152
    }
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc