/** * Handles additional arguments, sorting out any data- * prefixed tag attributes and assigning them. Then passes * the unassigned arguments to the parent class' method, * which in the default implementation will throw an error * about "undeclared argument used". * * @param array $arguments * @return void */ public function handleAdditionalArguments(array $arguments) { $unassigned = array(); foreach ($arguments as $argumentName => $argumentValue) { if (strpos($argumentName, 'data-') === 0) { $this->tag->addAttribute($argumentName, $argumentValue); } else { $unassigned[$argumentName] = $argumentValue; } } parent::handleAdditionalArguments($unassigned); }
/** * @return void */ public function initializeArguments() { parent::initializeArguments(); // @deprecated since 2.0 use the "image" argument instead $this->registerArgument('asset', AssetInterface::class, 'The image to be rendered - DEPRECATED, use the "image" argument instead', false); }
/** * @param AbstractViewHelper $viewHelper */ protected function injectDependenciesIntoViewHelper(AbstractViewHelper $viewHelper) { $viewHelper->setRenderingContext($this->renderingContext); $viewHelper->setArguments($this->arguments); if ($viewHelper instanceof AbstractTagBasedViewHelper) { $viewHelper->injectTagBuilder($this->tagBuilder); } }
/** * The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure. * These contain closures which are be executed to render the then(), respectively else() case. * * @param string $argumentsName * @param string $closureName * @param string $initializationPhpCode * @param ViewHelperNode $node * @param TemplateCompiler $compiler * @return string */ public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler) { $thenViewHelperEncountered = $elseViewHelperEncountered = false; foreach ($node->getChildNodes() as $childNode) { if ($childNode instanceof ViewHelperNode) { $viewHelperClassName = $childNode->getViewHelperClassName(); if (substr($viewHelperClassName, -14) === 'ThenViewHelper') { $thenViewHelperEncountered = true; $childNodesAsClosure = $compiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__thenClosure\'] = %s;', $argumentsName, $childNodesAsClosure) . chr(10); } elseif (substr($viewHelperClassName, -14) === 'ElseViewHelper') { $elseViewHelperEncountered = true; $childNodesAsClosure = $compiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__elseClosures\'][] = %s;', $argumentsName, $childNodesAsClosure) . chr(10); $arguments = $childNode->getArguments(); if (isset($arguments['if'])) { // The "else" has an argument, indicating it has a secondary (elseif) condition. // Compile a closure which will evaluate the condition. $elseIfConditionAsClosure = $compiler->wrapViewHelperNodeArgumentEvaluationInClosure($childNode, 'if'); $initializationPhpCode .= sprintf('%s[\'__elseifClosures\'][] = %s;', $argumentsName, $elseIfConditionAsClosure) . chr(10); } } } } if (!$thenViewHelperEncountered && !$elseViewHelperEncountered && !isset($node->getArguments()['then'])) { $initializationPhpCode .= sprintf('%s[\'__thenClosure\'] = %s;', $argumentsName, $closureName) . chr(10); } return parent::compile($argumentsName, $closureName, $initializationPhpCode, $node, $compiler); }