[FEATURE] Additional params for HtmlParser attribute userFunc 35/30935/7
authorAlexander Stehlik <alexander.stehlik@gmail.com>
Sun, 1 Feb 2015 12:34:41 +0000 (13:34 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 2 Mar 2015 19:41:53 +0000 (20:41 +0100)
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
typo3/sysext/core/Documentation/Changelog/master/Feature-59712-HtmlParserAdditionalUserFuncParams.rst [new file with mode: 0644]

index 150a9b0..a8d9f15 100644 (file)
@@ -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 (file)
index 0000000..1ef9647
--- /dev/null
@@ -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