44a291289637870d232b13cf19ee30b410af9193
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / CaseViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
20 use TYPO3Fluid\Fluid\ViewHelpers\DefaultCaseViewHelper;
21
22 /**
23 * Case view helper that is only usable within the SwitchViewHelper.
24 *
25 * @see \TYPO3Fluid\Fluid\ViewHelpers\SwitchViewHelper
26 *
27 * @api
28 */
29 class CaseViewHelper extends \TYPO3Fluid\Fluid\ViewHelpers\CaseViewHelper
30 {
31 /**
32 * Overrides the "value" argument definition, making it optional.
33 *
34 * @return void
35 */
36 public function initializeArguments() {
37 parent::initializeArguments();
38 $this->overrideArgument('value', 'mixed', 'Value to match in this case', false);
39 }
40
41 /**
42 * @param array $arguments
43 * @return void
44 */
45 public function handleAdditionalArguments(array $arguments) {
46 if (isset($arguments['default'])) {
47 GeneralUtility::deprecationLog('Argument "default" on f:case is deprecated - use f:defaultCase instead');
48 if ((bool)$arguments['default']) {
49 // Patch the ViewHelperNode (parse-time only) and change it's class name
50 $attribute = new \ReflectionProperty($this->viewHelperNode, 'viewHelperClassName');
51 $attribute->setAccessible(true);
52 $attribute->setValue($this->viewHelperNode, DefaultCaseViewHelper::class);
53 }
54 }
55 }
56
57 /**
58 * @param array $arguments
59 * @return void
60 */
61 public function validateAdditionalArguments(array $arguments) {
62 // Unset the "default" argument and let everything else through to be validated
63 unset($arguments['default']);
64 parent::validateAdditionalArguments($arguments);
65 }
66 }