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

FluidTYPO3 / vhs / 12968726888

25 Jan 2025 09:52PM UTC coverage: 72.324%. Remained the same
12968726888

push

github

NamelessCoder
[BUGFIX] Avoid PDO constants in favor of Connection constants

4 of 6 new or added lines in 3 files covered. (66.67%)

5553 of 7678 relevant lines covered (72.32%)

13.48 hits per line

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

41.94
/Classes/ViewHelpers/Condition/Page/IsLanguageViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Page;
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\Utility\DoctrineQueryProxy;
12
use TYPO3\CMS\Core\Context\Context;
13
use TYPO3\CMS\Core\Context\LanguageAspect;
14
use TYPO3\CMS\Core\Database\Connection;
15
use TYPO3\CMS\Core\Database\ConnectionPool;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
19

20
/**
21
 * ### Condition: Is current language
22
 *
23
 * A condition ViewHelper which renders the `then` child if
24
 * current language matches the provided language uid or language
25
 * title. When using language titles like 'de' it is required to
26
 * provide a default title to distinguish between the standard
27
 * and a non existing language.
28
 */
29
class IsLanguageViewHelper extends AbstractConditionViewHelper
30
{
31
    public function initializeArguments(): void
32
    {
33
        parent::initializeArguments();
6✔
34
        $this->registerArgument('language', 'string', 'language to check', true);
6✔
35
        $this->registerArgument('defaultTitle', 'string', 'title of the default language', false, 'en');
6✔
36
    }
37

38
    public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
39
    {
40
        if (!is_array($arguments)) {
6✔
41
            return false;
×
42
        }
43
        /** @var string $language */
44
        $language = $arguments['language'];
6✔
45
        /** @var string $defaultTitle */
46
        $defaultTitle = $arguments['defaultTitle'];
6✔
47

48
        if (class_exists(LanguageAspect::class)) {
6✔
49
            /** @var Context $context */
50
            $context = GeneralUtility::makeInstance(Context::class);
6✔
51
            /** @var LanguageAspect $languageAspect */
52
            $languageAspect = $context->getAspect('language');
6✔
53
            $currentLanguageUid = $languageAspect->getId();
6✔
54
        } else {
55
            $currentLanguageUid = $GLOBALS['TSFE']->sys_language_uid;
×
56
        }
57

58
        if (is_numeric($language)) {
6✔
59
            $languageUid = intval($language);
6✔
60
        } else {
61
            /** @var ConnectionPool $connectionPool */
62
            $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
×
63
            $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_language');
×
64

NEW
65
            $queryBuilder->createNamedParameter($language, Connection::PARAM_STR, ':title');
×
66

67
            $queryBuilder
×
68
                ->select('uid')
×
69
                ->from('sys_language')
×
70
                ->where(
×
71
                    $queryBuilder->expr()->eq('title', ':title')
×
72
                );
×
73
            $result = DoctrineQueryProxy::executeQueryOnQueryBuilder($queryBuilder);
×
74
            $row = DoctrineQueryProxy::fetchAssociative($result);
×
75

76
            if (is_array($row)) {
×
77
                /** @var int $languageUid */
78
                $languageUid = $row['uid'];
×
79
            } else {
80
                if ((string) $language === $defaultTitle) {
×
81
                    $languageUid = $currentLanguageUid;
×
82
                } else {
83
                    $languageUid = -1;
×
84
                }
85
            }
86
        }
87
        return $languageUid === $currentLanguageUid;
6✔
88
    }
89
}
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