[TYPO3-german] Re: ViewHelper-Rückgabe erneut in FLUID rendern?

Manuel Raaf raaf at badw.de
Thu Jul 27 11:39:54 CEST 2017


Sodale,

ich bin zwischenzeitlich auf eine Lösung gekommen (durch Mithilfe eines Kollegen, der wesentlich länger Extensions entwickelt, aber bisher auch noch nie den beschriebenen Bedarf hatte): 

Ich hole mir den Text via renderChildren(), verarbeite und prüfe ihn auf die Textmuster, die ich dann im ViewHelper durch gerenderte Tags ersetze und dann einfach wieder als Text zurückgebe. Letztlich ist mein Kernproblem in 4 Zeilen Code gelöst. 

Mein ViewHelper leitet von \TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper ab, nicht vom AbstractViewHelper. 
In PHP 5.6 überschreibe ich render() wie folgt:

/**
     * @param string $action
     * @param array $arguments 
     * @param string $controller
*/
public function render($action = null, array $arguments = [], $controller = null)
{
$sigel= $this->renderChildren();
#
# Text zum $sigel wird geholt, verarbeitet und mit preg_match_all() auf Muster geprüft, die dann im Anschluss in ActionLinks gesetzt werden sollen
#
#
# Die nächsten 4 Zeilen lösen das Kernproblem:
$uriBuilder = $this->controllerContext->getUriBuilder();
$uri = $uriBuilder->reset()->uriFor($action, $arguments, $controller);
$this->tag->setContent($match[0]);
$this->tag->forceClosingTag(true);
$str = str_replace($match[0], $this->tag->render(), $str);
#
# sonstiger Code; Schleifenende
#
return $str;
}

Diese Zeilen sind in einer Schleife, die die Treffer von preg_mach_all() durchläuft. 

Im Template habe ich den Aufruf via <...action="list" controller="Literatur" arguments="{searchSubmitted : 2, literaturKurztitel : ''}">{element.textSigel}</...>


In PHP 7 muss man entweder warnings deaktivieren ODER aber die Funktion render() 1:1 überschreiben, d.h. dass die eigene render() exakt die gleichen Parameter benötigt, wie die der Originalklasse. Andernfalls kommt ein php:warning, dass die Strukur nicht identisch ist, und TYPO3 steigt aus. Der Vollständigkeit halber hier der 1:1-kopierte Code:

/**
     * @param string $action Target action
     * @param array $arguments Arguments
     * @param string $controller Target controller. If NULL current controllerName is used
     * @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used
     * @param string $pluginName Target plugin. If empty, the current plugin name is used
     * @param int $pageUid target page. See TypoLink destination
     * @param int $pageType type of the target page. See typolink.parameter
     * @param bool $noCache set this to disable caching for the target page. You should not need this.
     * @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
     * @param string $section the anchor to be added to the URI
     * @param string $format The requested format, e.g. ".html
     * @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
     * @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
     * @param bool $absolute If set, the URI of the rendered link is absolute
     * @param bool $addQueryString If set, the current query parameters will be kept in the URI
     * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
     * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
     * @return string Rendered link
     */
    public function render($action = null, array $arguments = [], $controller = null, $extensionName = null, $pluginName = null, $pageUid = null, $pageType = 0, $noCache = false, $noCacheHash = false, $section = '', $format = '', $linkAccessRestrictedPages = false, array $additionalParams = [], $absolute = false, $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $addQueryStringMethod = null)
    { ..... }


Viele Grüße,
Manuel


More information about the TYPO3-german mailing list