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

FluidTYPO3 / vhs / 13566190336

27 Feb 2025 12:18PM UTC coverage: 72.127% (-0.6%) from 72.746%
13566190336

push

github

NamelessCoder
[TER] 7.1.0

5649 of 7832 relevant lines covered (72.13%)

20.01 hits per line

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

41.33
/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\Proxy\DoctrineQueryProxy;
12
use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
13
use FluidTYPO3\Vhs\Utility\ContentObjectFetcher;
14
use TYPO3\CMS\Core\Context\Context;
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\Utility\GeneralUtility;
19
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
20
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
21
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
23

24
/**
25
 * ViewHelper to access data of the current content element record.
26
 */
27
class InfoViewHelper extends AbstractViewHelper
28
{
29
    use TemplateVariableViewHelperTrait;
30

31
    /**
32
     * @var boolean
33
     */
34
    protected $escapeOutput = false;
35

36
    /**
37
     * @var ConfigurationManagerInterface
38
     */
39
    protected $configurationManager;
40

41
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager): void
42
    {
43
        $this->configurationManager = $configurationManager;
21✔
44
    }
45

46
    public function initializeArguments(): void
47
    {
48
        $this->registerAsArgument();
7✔
49
        $this->registerArgument(
7✔
50
            'contentUid',
7✔
51
            'integer',
7✔
52
            'If specified, this UID will be used to fetch content element data instead of using the current ' .
7✔
53
            'content element.',
7✔
54
            false,
7✔
55
            0
7✔
56
        );
7✔
57
        $this->registerArgument(
7✔
58
            'field',
7✔
59
            'string',
7✔
60
            'If specified, only this field will be returned/assigned instead of the complete content element record.'
7✔
61
        );
7✔
62
    }
63

64
    /**
65
     * @return mixed
66
     * @throws \Exception
67
     */
68
    public function render()
69
    {
70
        /** @var int $contentUid */
71
        $contentUid = $this->arguments['contentUid'];
7✔
72
        $record = false;
7✔
73

74
        if (0 === $contentUid) {
7✔
75
            $cObj = ContentObjectFetcher::resolve($this->configurationManager);
7✔
76

77
            if ($cObj === null) {
7✔
78
                throw new Exception('v:content.info requires a ContentObjectRenderer, none found', 1737807859);
×
79
            }
80

81
            if ($cObj->getCurrentTable() !== 'tt_content') {
7✔
82
                throw new Exception(
×
83
                    'v:content.info must have contentUid argument outside tt_content context',
×
84
                    1690035521
×
85
                );
×
86
            }
87
            if (!empty($cObj->data)) {
7✔
88
                $record = $cObj->data;
7✔
89
            } else {
90
                $tsfe = $GLOBALS['TSFE'] ?? null;
×
91
                if (!$tsfe instanceof TypoScriptFrontendController) {
×
92
                    throw new Exception(
×
93
                        'v:content.info must have contentUid argument when no TypoScriptFrontendController exists',
×
94
                        1690035521
×
95
                    );
×
96
                }
97
                $recordReference = $tsfe->currentRecord;
×
98
                $contentUid = (int) substr($recordReference, strpos($recordReference, ':') + 1);
×
99
            }
100
        }
101

102
        /** @var string $field */
103
        $field = $this->arguments['field'];
7✔
104
        $selectFields = $field;
7✔
105

106
        if (!$record && 0 !== $contentUid) {
7✔
107
            if (!isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
×
108
                $selectFields = '*';
×
109
            }
110

111
            /** @var ConnectionPool $connectionPool */
112
            $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
×
113
            $queryBuilder = $connectionPool->getQueryBuilderForTable('tt_content');
×
114
            $queryBuilder->createNamedParameter($contentUid, Connection::PARAM_INT, ':uid');
×
115

116
            $queryBuilder
×
117
                ->select($selectFields)
×
118
                ->from('tt_content')
×
119
                ->where(
×
120
                    $queryBuilder->expr()->eq('uid', ':uid')
×
121
                );
×
122
            $result = DoctrineQueryProxy::executeQueryOnQueryBuilder($queryBuilder);
×
123
            $record = DoctrineQueryProxy::fetchAssociative($result);
×
124

125
            // Add the page overlay
126
            if (class_exists(LanguageAspect::class)) {
×
127
                /** @var Context $context */
128
                $context = GeneralUtility::makeInstance(Context::class);
×
129
                /** @var LanguageAspect $languageAspect */
130
                $languageAspect = $context->getAspect('language');
×
131
                $languageUid = $languageAspect->getId();
×
132
            } else {
133
                $languageUid = $GLOBALS['TSFE']->sys_language_uid;
×
134
            }
135

136
            if (0 !== $languageUid && $GLOBALS['TSFE']->sys_language_contentOL) {
×
137
                $record = $GLOBALS['TSFE']->sys_page->getRecordOverlay(
×
138
                    'tt_content',
×
139
                    $record,
×
140
                    $GLOBALS['TSFE']->sys_language_content,
×
141
                    $GLOBALS['TSFE']->sys_language_contentOL
×
142
                );
×
143
            }
144
        }
145

146
        if ($record === false) {
7✔
147
            throw new \Exception(
×
148
                sprintf('Either record with uid %d or field %s do not exist.', $contentUid, $selectFields),
×
149
                1358679983
×
150
            );
×
151
        }
152

153
        // Check if single field or whole record should be returned
154
        $content = null;
7✔
155
        if (null === $field) {
7✔
156
            $content = $record;
7✔
157
        } elseif (isset($record[$field])) {
×
158
            $content = $record[$field];
×
159
        }
160

161
        return $this->renderChildrenWithVariableOrReturnInput($content);
7✔
162
    }
163
}
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