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

FluidTYPO3 / vhs / 28026578140

23 Jun 2026 12:35PM UTC coverage: 71.202% (-0.2%) from 71.402%
28026578140

Pull #1977

github

web-flow
Merge b23e7e66c into 557bc4cc1
Pull Request #1977: [TASK] Clean up record/FAL ViewHelpers pattern

50 of 75 new or added lines in 4 files covered. (66.67%)

4903 of 6886 relevant lines covered (71.2%)

14.62 hits per line

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

35.71
/Classes/ViewHelpers/Page/Resources/FalViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Resources;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs 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\Vhs\Service\PageService;
12
use FluidTYPO3\Vhs\Traits\ArgumentOverride;
13
use FluidTYPO3\Vhs\Traits\SlideViewHelperTrait;
14
use FluidTYPO3\Vhs\Utility\RequestResolver;
15
use FluidTYPO3\Vhs\ViewHelpers\Resource\Record\FalViewHelper as ResourcesFalViewHelper;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17

18
/**
19
 * Page FAL resource ViewHelper.
20
 *
21
 * Do not use the "uid" argument in the "Preview" section.
22
 * Instead, use the "record" argument and pass the entire record.
23
 * This bypasses visibility restrictions that normally apply when you attempt
24
 * to load a record by UID through TYPO3's PageRepository, which is what the
25
 * resource ViewHelpers do if you only pass uid.
26
 */
27
class FalViewHelper extends ResourcesFalViewHelper
28
{
29
    use SlideViewHelperTrait;
30
    use ArgumentOverride;
31

32
    const DEFAULT_TABLE = 'pages';
33
    const DEFAULT_FIELD = 'media';
34

35
    protected string $table = self::DEFAULT_TABLE;
36
    protected string $field = self::DEFAULT_FIELD;
37

38
    public function initializeArguments(): void
39
    {
40
        parent::initializeArguments();
7✔
41

42
        $this->overrideArgument('table', 'string', 'The table to lookup records.', false, static::DEFAULT_TABLE);
7✔
43
        $this->overrideArgument(
7✔
44
            'field',
7✔
45
            'string',
7✔
46
            'The field of the table associated to resources.',
7✔
47
            false,
7✔
48
            static::DEFAULT_FIELD
7✔
49
        );
7✔
50
        $this->registerSlideArguments();
7✔
51
    }
52

53
    public function getRecord(int $id): ?array
54
    {
55
        $record = parent::getRecord($id);
×
56
        if (!$this->isDefaultLanguage() && $record !== null) {
×
57
            /** @var PageService $pageService */
58
            $pageService = GeneralUtility::makeInstance(PageService::class);
×
59
            $pageRepository = $pageService->getPageRepository();
×
60
            $localisation = $pageRepository->getPageOverlay($record, $this->getCurrentLanguageUid());
×
61
            if (is_array($localisation)) {
×
62
                $record = $localisation;
×
63
            }
64
        }
65
        return $record;
×
66
    }
67

68
    public function getResources(array $record): array
69
    {
70
        return $this->getSlideRecords($record['uid']);
×
71
    }
72

73
    protected function getSlideRecordsFromPage(int $pageUid, ?int $limit): array
74
    {
75
        $pageRecord = $this->getRecord($pageUid);
×
76
        if ($pageRecord === null) {
×
77
            return [];
×
78
        }
79
        // NB: we call parent::getResources intentionally, as to not call the overridden
80
        // method on this class. Calling $this->getResources() would yield wrong result
81
        // for the purpose of this method.
82
        $resources = parent::getResources($pageRecord);
×
83
        if (null !== $limit && count($resources) > $limit) {
×
84
            $resources = array_slice($resources, 0, $limit);
×
85
        }
86
        return $resources;
×
87
    }
88

89
    protected function isDefaultLanguage(): bool
90
    {
91
        return $this->getCurrentLanguageUid() === 0;
×
92
    }
93

94
    protected function getCurrentLanguageUid(): int
95
    {
NEW
96
        return RequestResolver::getLanguage()->getLanguageId();
×
97
    }
98
}
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