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

FluidTYPO3 / vhs / 28586903276

02 Jul 2026 11:35AM UTC coverage: 69.743%. First build
28586903276

Pull #1986

github

web-flow
Merge 1e176521f into c7a426854
Pull Request #1986: [TASK] Update test base class

9 of 25 new or added lines in 1 file covered. (36.0%)

4829 of 6924 relevant lines covered (69.74%)

4.32 hits per line

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

55.32
/Classes/ViewHelpers/Content/InfoViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Content;
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\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Proxy\DoctrineQueryProxy;
13
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
14
use FluidTYPO3\Vhs\Utility\RequestResolver;
15
use TYPO3\CMS\Core\Context\LanguageAspect;
16
use TYPO3\CMS\Core\Database\Connection;
17
use TYPO3\CMS\Core\Database\ConnectionPool;
18
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21

22
/**
23
 * ViewHelper to access data of a content element record.
24
 */
25
class InfoViewHelper extends AbstractViewHelper
26
{
27
    use TemplateVariableViewHelperTrait;
28

29
    /**
30
     * @var boolean
31
     */
32
    protected $escapeOutput = false;
33

34
    /**
35
     * @var ConfigurationManagerInterface
36
     */
37
    protected $configurationManager;
38

39
    /**
40
     * @var PageRepository
41
     */
42
    protected $pageRepository;
43

44
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
45
    {
46
        $this->configurationManager = $configurationManager;
6✔
47
    }
48

49
    public function injectPageRepository(PageRepository $pageRepository): void
50
    {
NEW
51
        $this->pageRepository = $pageRepository;
×
52
    }
53

54
    public function initializeArguments(): void
55
    {
56
        $this->registerAsArgument();
4✔
57
        $this->registerArgument(
4✔
58
            'contentUid',
4✔
59
            'integer',
4✔
60
            'This UID will be used to fetch content element data.',
4✔
61
            true
4✔
62
        );
4✔
63
        $this->registerArgument(
4✔
64
            'field',
4✔
65
            'string',
4✔
66
            'If specified, only this field will be returned/assigned instead of the complete content element record.'
4✔
67
        );
4✔
68
    }
69

70
    public function render(): mixed
71
    {
72
        /** @var int $contentUid */
73
        $contentUid = $this->arguments['contentUid'];
2✔
74

75
        /** @var string|null $field */
76
        $field = $this->arguments['field'];
2✔
77
        $selectFields = $field;
2✔
78

79
        if (!$field || !isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
2✔
80
            $selectFields = '*';
2✔
81
        }
82

83
        $record = $this->fetchRecord($selectFields ?? '*', $contentUid);
2✔
84

85
        $languageUid = RequestResolver::getLanguage()->getLanguageId();
2✔
86

87
        if ($languageUid && $record && $record['sys_language_uid'] !== $languageUid) {
2✔
NEW
88
            $languageAspect = new LanguageAspect(RequestResolver::getLanguage()->getLanguageId());
×
NEW
89
            $record = $this->pageRepository->getLanguageOverlay('tt_content', $record, $languageAspect);
×
90
        }
91

92
        if (!$record) {
2✔
93
            throw new \Exception(
×
NEW
94
                sprintf('Either record with uid %d or field %s does not exist.', $contentUid, $selectFields),
×
95
                1358679983
×
96
            );
×
97
        }
98

99
        // Check if single field or whole record should be returned
100
        $content = null;
2✔
101
        if (!$field) {
2✔
102
            $content = $record;
2✔
103
        } elseif (isset($record[$field])) {
×
104
            $content = $record[$field];
×
105
        }
106

107
        return $this->renderChildrenWithVariableOrReturnInput($content);
2✔
108
    }
109

110
    protected function fetchRecord(string $field, int $uid): ?array
111
    {
112
        /** @var ConnectionPool $connectionPool */
NEW
113
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
×
NEW
114
        $queryBuilder = $connectionPool->getQueryBuilderForTable('tt_content');
×
NEW
115
        $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT, ':uid');
×
116

NEW
117
        $queryBuilder
×
NEW
118
            ->select($field)
×
NEW
119
            ->from('tt_content')
×
NEW
120
            ->where(
×
NEW
121
                $queryBuilder->expr()->eq('uid', ':uid')
×
NEW
122
            );
×
NEW
123
        $result = DoctrineQueryProxy::executeQueryOnQueryBuilder($queryBuilder);
×
NEW
124
        $record = DoctrineQueryProxy::fetchAssociative($result);
×
NEW
125
        return $record;
×
126
    }
127
}
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