From abac3032c8878d6698beda7800bee0557c414d62 Mon Sep 17 00:00:00 2001 From: Alexander Stehlik <alexander.stehlik@gmail.com> Date: Sun, 1 Feb 2015 13:34:41 +0100 Subject: [PATCH] [FEATURE] Additional params for HtmlParser attribute userFunc Sub parameters passed to the HtmlParser tag configuration like: fixAttrib.[attribute].userFunc.myparam = test1 will be passed to the configured user function in an array. The attribute value will be stored in the attributeValue array key. To keep backward compatibility the attribute value will be passed as string to the user function when no additional attributes exist. Releases: master Resolves: #59712 Change-Id: Ib073dad0759fa2b20a82bf976f8d04f39d9135f0 Reviewed-on: http://review.typo3.org/30935 Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- typo3/sysext/core/Classes/Html/HtmlParser.php | 7 ++- ...712-HtmlParserAdditionalUserFuncParams.rst | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-59712-HtmlParserAdditionalUserFuncParams.rst diff --git a/typo3/sysext/core/Classes/Html/HtmlParser.php b/typo3/sysext/core/Classes/Html/HtmlParser.php index 150a9b0572d4..a8d9f157a1a5 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 000000000000..1ef9647bd401 --- /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 -- GitLab