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

FluidTYPO3 / flux / 12929786239

23 Jan 2025 01:03PM UTC coverage: 92.829% (-0.07%) from 92.901%
12929786239

Pull #2209

github

web-flow
Merge 1e194cbc7 into cf49f7a79
Pull Request #2209: [WIP] Compatibility with TYPO3 v13

86 of 112 new or added lines in 31 files covered. (76.79%)

5 existing lines in 3 files now uncovered.

7055 of 7600 relevant lines covered (92.83%)

65.02 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;
35✔
52
        $this->basePath = $basePath;
35✔
53
        $this->relativeFilePath = $relativeFilePath;
35✔
54
        $this->providerClassName = $providerClassName;
35✔
55
    }
56

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

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

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

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

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

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

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

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

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

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

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

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

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

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