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

FluidTYPO3 / flux / 27757675993

18 Jun 2026 11:55AM UTC coverage: 89.162% (-3.5%) from 92.646%
27757675993

push

github

NamelessCoder
[TASK] Address last phpstan warnings

6228 of 6985 relevant lines covered (89.16%)

40.84 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
namespace FluidTYPO3\Flux\Content\TypeDefinition\FluidFileBased;
3

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

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

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

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

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

66
        if ($provider === null) {
8✔
67
            return $defaultForm;
4✔
68
        }
69
        return $provider->getForm($record) ?? $defaultForm;
4✔
70
    }
71

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

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

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

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

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

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

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

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

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

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

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

146
    protected function getProviderResolver(): ProviderResolver
147
    {
148
        /** @var ProviderResolver $providerResolver */
149
        $providerResolver = GeneralUtility::makeInstance(ProviderResolver::class);
16✔
150
        return $providerResolver;
16✔
151
    }
152
}
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