[FEATURE] displayCond should allow userFunc as condition 28/34728/6
authorSebastian Fischer <typo3@evoweb.de>
Fri, 28 Nov 2014 08:56:19 +0000 (09:56 +0100)
committerBenjamin Mack <benni@typo3.org>
Sat, 3 Jan 2015 14:11:49 +0000 (15:11 +0100)
This patch enables the usage of a displayCond defined as
'USER:\Example\Namespace\UserClass->functionName:any:other:parameter'

Releases: master
Resolves: #62944
Change-Id: I9e915e9098494715a3fb5961836af6b16eb12b27
Reviewed-on: http://review.typo3.org/34728
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/ElementConditionMatcher.php
typo3/sysext/core/Documentation/Changelog/master/Feature-62944-UserFuncAsDisplayCond.rst [new file with mode: 0644]

index c904ea3..116bd06 100644 (file)
@@ -141,6 +141,9 @@ class ElementConditionMatcher {
                        case 'VERSION':
                                $result = $this->matchVersionCondition($condition);
                                break;
+                       case 'USER':
+                               $result = $this->matchUserCondition($condition);
+                               break;
                }
                return $result;
        }
@@ -330,4 +333,22 @@ class ElementConditionMatcher {
                return $GLOBALS['BE_USER'];
        }
 
+       /**
+        * Evaluates via the referenced user-defined method
+        *
+        * @param string $condition
+        * @return bool
+        */
+       protected function matchUserCondition($condition) {
+               $conditionParameters = explode(':', $condition);
+               $userFunction = array_shift($conditionParameters);
+
+               $parameter = array(
+                       'record' => $this->record,
+                       'flexformValueKey' => $this->flexformValueKey,
+                       'conditionParameters' => $conditionParameters
+               );
+
+               return (bool)\TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunction, $parameter, $this);
+       }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-62944-UserFuncAsDisplayCond.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-62944-UserFuncAsDisplayCond.rst
new file mode 100644 (file)
index 0000000..7024bd2
--- /dev/null
@@ -0,0 +1,19 @@
+=========================================================
+Feature: #62944 - UserFunc available as Display Condition
+=========================================================
+
+Description
+===========
+
+Being able to use userFunc as displayCondition makes it possible to
+check on any imaginable condition or state. If any situation can not
+be evaluated with any of the existing checks the developer is free
+to add an own user function which provides a boolean result whether
+to show or hide the TCA field.
+
+.. code-block:: php
+$GLOBALS['TCA']['tt_content']['columns']['bodytext']['displayCond'] =
+       'USER:Evoweb\\Example\\User\\ElementConditionMatcher->checkHeaderGiven:any:more:information';
+
+Divided by colons any parameters can be added that are sent to the ConditionMatcher class.
+