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

FluidTYPO3 / vhs / 12968595783

25 Jan 2025 09:30PM UTC coverage: 72.268%. Remained the same
12968595783

Pull #1925

github

web-flow
Merge aa1eb976f into 0ca5a1c10
Pull Request #1925: [BUGFIX] Replace all evaluateCondition methods with verdict methods

19 of 27 new or added lines in 9 files covered. (70.37%)

25 existing lines in 4 files now uncovered.

5548 of 7677 relevant lines covered (72.27%)

13.46 hits per line

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

81.82
/Classes/ViewHelpers/Condition/Form/HasValidatorViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Condition\Form;
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 TYPO3\CMS\Core\Utility\GeneralUtility;
12
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
13
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
14
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
15
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
16
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
17

18
/**
19
 * ### Form: Field Has Validator?
20
 *
21
 * Takes a property (dotted path supported) and renders the
22
 * then-child if the property at the given path has any
23
 * @validate annotation.
24
 */
25
class HasValidatorViewHelper extends AbstractConditionViewHelper
26
{
27
    public function initializeArguments(): void
28
    {
29
        parent::initializeArguments();
12✔
30
        $this->registerArgument(
12✔
31
            'property',
12✔
32
            'string',
12✔
33
            'The property name, dotted path supported, to determine required.',
12✔
34
            true
12✔
35
        );
12✔
36
        $this->registerArgument(
12✔
37
            'validatorName',
12✔
38
            'string',
12✔
39
            'The name of the validator that must exist for the condition to be true.',
12✔
40
            true
12✔
41
        );
12✔
42
        $this->registerArgument(
12✔
43
            'object',
12✔
44
            DomainObjectInterface::class,
12✔
45
            'Optional object - if not specified, grabs the associated form object.',
12✔
46
            true
12✔
47
        );
12✔
48
    }
49

50
    public static function verdict(array $arguments, RenderingContextInterface $renderingContext): bool
51
    {
52
        if (!is_array($arguments)) {
36✔
53
            return false;
×
54
        }
55

56
        /** @var ReflectionService $reflectionService */
57
        $reflectionService = GeneralUtility::makeInstance(ReflectionService::class);
36✔
58

59
        $property = $arguments['property'];
36✔
60
        $validatorName = $arguments['validatorName'] ?? null;
36✔
61
        $object = $arguments['object'] ?? null;
36✔
62

63
        $path = null;
36✔
64
        if (strpos($property, '.') !== false) {
36✔
65
            $parts = explode('.', $property);
24✔
66
            $property = array_pop($parts);
24✔
67
            $path = implode('.', $parts);
24✔
68
            $object = ObjectAccess::getPropertyPath($object, $path);
24✔
69
        }
70

71
        if (!is_object($object)) {
36✔
72
            return false;
24✔
73
        }
74

75
        if (!method_exists($reflectionService, 'getPropertyTagValues')) {
12✔
76
            // TYPO3 version no longer contains the raw property tag value extractor. Instead, we can check for a given
77
            // validator by extracting the validators and analysing those.
78
            $validators = $reflectionService->getClassSchema($object)->getProperty($property)->getValidators();
12✔
79
            foreach ($validators as $validatorConfiguration) {
12✔
UNCOV
80
                if ($validatorConfiguration['name'] === $validatorName) {
×
81
                    return true;
×
82
                }
83
            }
84
            return false;
12✔
85
        }
86

UNCOV
87
        $className = get_class($object);
×
88
        $annotations = $reflectionService->getPropertyTagValues($className, $property, 'validate');
×
89
        if (empty($annotations)) {
×
90
            // We tried looking for the legacy validator name but found none. Retry with the new way. We have to do this
91
            // as a retry, because we cannot assume that any site using TYPO3 9.1+ will also be using the modern
92
            // annotations. Hence we cannot change the validator name until we've also looked for the legacy ones (which
93
            // will take priority if found).
UNCOV
94
            $annotations = $reflectionService->getPropertyTagValues($className, $property, 'Extbase\\Validate');
×
95
        }
UNCOV
96
        return (count($annotations) && (!$validatorName || in_array($validatorName, $annotations)));
×
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