diff --git a/typo3/sysext/core/Classes/Html/HtmlParser.php b/typo3/sysext/core/Classes/Html/HtmlParser.php index 150a9b0572d436b05595b96db8ded2c484147f0d..a8d9f157a1a580039afb85dffabcf96b078ccc5b 100644 --- a/typo3/sysext/core/Classes/Html/HtmlParser.php +++ b/typo3/sysext/core/Classes/Html/HtmlParser.php @@ -880,7 +880,12 @@ class HtmlParser { } } if ($params['userFunc']) { - $tagAttrib[0][$attr] = GeneralUtility::callUserFunction($params['userFunc'], $tagAttrib[0][$attr], $this); + if (is_array($params['userFunc.'])) { + $params['userFunc.']['attributeValue'] = $tagAttrib[0][$attr]; + } else { + $params['userFunc.'] = $tagAttrib[0][$attr]; + } + $tagAttrib[0][$attr] = GeneralUtility::callUserFunction($params['userFunc'], $params['userFunc.'], $this); } } } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-59712-HtmlParserAdditionalUserFuncParams.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-59712-HtmlParserAdditionalUserFuncParams.rst new file mode 100644 index 0000000000000000000000000000000000000000..1ef9647bd40160052166ec6e786de877884398d2 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-59712-HtmlParserAdditionalUserFuncParams.rst @@ -0,0 +1,48 @@ +=========================================================== +Feature: #59712 - Additional params for HTMLparser userFunc +=========================================================== + +Description +=========== + +It is now possible to supply additional parameters to a userFunc of the HTMLparser: + +:: + + myobj = TEXT + myobj.value = <a href="/" class="myclass">MyText</a> + myobj.HTMLparser.tags.a.fixAttrib.class { + userFunc = Tx\MyExt\Myclass->htmlUserFunc + userFunc.myparam = test1 + } + +By default only the value of the processed attribute is passed to the userFunc +as the first parameter: + +:: + + function htmlUserFunc($attributeValue, HtmlParser $htmlParser) { + // $attributeValue is set to the current attribute value "myclass" + } + +When additional options are provided as described above, these options will be +passed in the first function parameter as an array. The attribute value is passed +in the array with the ```attributeValue``` array key. + +:: + + function htmlUserFunc(array $params, HtmlParser $htmlParser) { + // $params['attributeValue'] contains the current attribute value "myclass". + // $params['myparam'] is set to "test" in the current example. + } + + +Impact +====== + +If additional parameters are provided to the HTMLparser userFunc setting the first parameter +passed to the called function changes from a string with the attribute value to an array +containing the attributeValue key and all additional settings. + +This has an impact to all installations where additional parameters are used in the userFunc +setting of the HTMLparser. \ No newline at end of file