|
1
|
|
|
<?php |
|
2
|
|
|
namespace TYPO3Fluid\Fluid\Core\ViewHelper\Traits; |
|
3
|
|
|
|
|
4
|
|
|
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler; |
|
5
|
|
|
use TYPO3Fluid\Fluid\Core\Compiler\ViewHelperCompiler; |
|
6
|
|
|
use TYPO3Fluid\Fluid\Core\Exception; |
|
7
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class CompilableWithContentArgumentAndRenderStatic |
|
11
|
|
|
* |
|
12
|
|
|
* Provides default methods for rendering and compiling |
|
13
|
|
|
* any ViewHelper that conforms to the `renderStatic` |
|
14
|
|
|
* method pattern but has the added common use case that |
|
15
|
|
|
* an argument value must be checked and used instead of |
|
16
|
|
|
* the normal render children closure, if that named |
|
17
|
|
|
* argument is specified and not empty. |
|
18
|
|
|
* |
|
19
|
|
|
* @deprecated Trait no longer required, content argument supported by any VH via base class. |
|
20
|
|
|
*/ |
|
21
|
|
|
trait CompileWithContentArgumentAndRenderStatic |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Default render method to render ViewHelper with |
|
25
|
|
|
* first defined optional argument as content. |
|
26
|
|
|
* |
|
27
|
|
|
* @return string Rendered string |
|
28
|
|
|
* @api |
|
29
|
|
|
*/ |
|
30
|
|
|
public function render() |
|
31
|
|
|
{ |
|
32
|
|
|
return static::renderStatic( |
|
|
|
|
|
|
33
|
|
|
$this->arguments, |
|
|
|
|
|
|
34
|
|
|
$this->buildRenderChildrenClosure(), |
|
|
|
|
|
|
35
|
|
|
$this->renderingContext |
|
|
|
|
|
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function resolveContentArgumentName() |
|
43
|
|
|
{ |
|
44
|
|
|
if (empty($this->contentArgumentName)) { |
|
45
|
|
|
$registeredArguments = call_user_func_array([$this, 'prepareArguments'], []); |
|
46
|
|
|
foreach ($registeredArguments as $registeredArgument) { |
|
47
|
|
|
if (!$registeredArgument->isRequired()) { |
|
48
|
|
|
$this->contentArgumentName = $registeredArgument->getName(); |
|
|
|
|
|
|
49
|
|
|
return $this->contentArgumentName; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
throw new Exception( |
|
53
|
|
|
sprintf('Attempting to compile %s failed. Chosen compile method requires that ViewHelper has ' . |
|
54
|
|
|
'at least one registered and optional argument', __CLASS__) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
return $this->contentArgumentName; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.