[TASK] Use makeInstance in some hooks 21/40621/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 25 Jun 2015 12:06:50 +0000 (14:06 +0200)
committerFrank Nägler <frank.naegler@typo3.org>
Thu, 25 Jun 2015 17:29:53 +0000 (19:29 +0200)
Switch some hooks from getUserObj() to makeInstance() and
rely on auto loading.

Resolves: #67749
Releases: master
Change-Id: Ib89e920fd50a40103a38eedb229382d547de62e1
Reviewed-on: http://review.typo3.org/40621
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Form/Element/InputElement.php
typo3/sysext/backend/Classes/Form/Element/TextElement.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-67749-ForceAutoloadingForVariousHooks.rst [new file with mode: 0644]
typo3/sysext/saltedpasswords/ext_localconf.php
typo3/sysext/setup/Classes/Controller/SetupModuleController.php

index fe08548..fc1ac68 100644 (file)
@@ -130,6 +130,7 @@ class InputElement extends AbstractFormElement {
                        }
                }
 
+               // @todo: The whole eval handling is a mess and needs refactoring
                foreach ($evalList as $func) {
                        switch ($func) {
                                case 'required':
@@ -150,13 +151,19 @@ class InputElement extends AbstractFormElement {
                                        }
                                        break;
                                default:
+                                       // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
+                                       // @todo: keyword like "date", or a class reference. The global registration could be dropped then
                                        // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
-                                       $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
-                                       if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
-                                               $_params = array(
-                                                       'value' => $parameterArray['itemFormElValue']
-                                               );
-                                               $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
+                                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
+                                               if (class_exists($func)) {
+                                                       $evalObj = GeneralUtility::makeInstance($func);
+                                                       if (method_exists($evalObj, 'deevaluateFieldValue')) {
+                                                               $_params = array(
+                                                                       'value' => $parameterArray['itemFormElValue']
+                                                               );
+                                                               $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
+                                                       }
+                                               }
                                        }
                        }
                }
@@ -208,11 +215,17 @@ class InputElement extends AbstractFormElement {
                $html .= '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
 
                $resultArray['extJSCODE'] = 'typo3form.fieldSet(' . $paramsList . ');';
+
                // Going through all custom evaluations configured for this field
+               // @todo: Similar to above code!
                foreach ($evalList as $evalData) {
-                       $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData] . ':&' . $evalData);
-                       if (is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
-                               $resultArray['extJSCODE'] .= LF . 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '}';
+                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData])) {
+                               if (class_exists($evalData)) {
+                                       $evalObj = GeneralUtility::makeInstance($evalData);
+                                       if (method_exists($evalObj, 'returnFieldJS')) {
+                                               $resultArray['extJSCODE'] .= LF . 'TBE_EDITOR.customEvalFunctions[' . GeneralUtility::quoteJSvalue($evalData) . '] = function(value) {' . $evalObj->returnFieldJS() . '}';
+                                       }
+                               }
                        }
                }
 
index 9ab6a95..47d882a 100644 (file)
@@ -116,13 +116,20 @@ class TextElement extends AbstractFormElement {
                                if ($func === 'required') {
                                        $resultArray['requiredFields'][$table . '_' . $row['uid'] . '_' . $fieldName] = $parameterArray['itemFormElName'];
                                } else {
-                                       // Hint: There is a similar hook for "evaluateFieldValue" in DataHandler
-                                       $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
-                                       if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
-                                               $_params = array(
-                                                       'value' => $parameterArray['itemFormElValue']
-                                               );
-                                               $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
+                                       // @todo: This is ugly: The code should find out on it's own whether a eval definition is a
+                                       // @todo: keyword like "date", or a class reference. The global registration could be dropped then
+                                       // Pair hook to the one in \TYPO3\CMS\Core\DataHandling\DataHandler::checkValue_input_Eval()
+                                       // There is a similar hook for "evaluateFieldValue" in DataHandler and InputElement
+                                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
+                                               if (class_exists($func)) {
+                                                       $evalObj = GeneralUtility::makeInstance($func);
+                                                       if (method_exists($evalObj, 'deevaluateFieldValue')) {
+                                                               $_params = array(
+                                                                       'value' => $parameterArray['itemFormElValue']
+                                                               );
+                                                               $parameterArray['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
+                                                       }
+                                               }
                                        }
                                }
                        }
index ea2482d..3e4a049 100644 (file)
@@ -2654,12 +2654,13 @@ class DataHandler {
                                        }
                                        break;
                                default:
-                                       if (empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
-                                               break;
-                                       }
-                                       $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
-                                       if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
-                                               $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
+                                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
+                                               if (class_exists($func)) {
+                                                       $evalObj = GeneralUtility::makeInstance($func);
+                                                       if (method_exists($evalObj, 'evaluateFieldValue')) {
+                                                               $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
+                                                       }
+                                               }
                                        }
                        }
                }
@@ -2766,12 +2767,13 @@ class DataHandler {
                                        $this->checkValue_input_ValidateEmail($value, $set);
                                        break;
                                default:
-                                       if (empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
-                                               break;
-                                       }
-                                       $evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
-                                       if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
-                                               $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
+                                       if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
+                                               if (class_exists($func)) {
+                                                       $evalObj = GeneralUtility::makeInstance($func);
+                                                       if (method_exists($evalObj, 'evaluateFieldValue')) {
+                                                               $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
+                                                       }
+                                               }
                                        }
                        }
                }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-67749-ForceAutoloadingForVariousHooks.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-67749-ForceAutoloadingForVariousHooks.rst
new file mode 100644 (file)
index 0000000..6e36fd3
--- /dev/null
@@ -0,0 +1,38 @@
+=============================================================
+Breaking: #67749 - Force class auto loading for various hooks
+=============================================================
+
+Description
+===========
+
+Some hook registrations now rely on class auto loading.
+
+
+Impact
+======
+
+Hooks may not be called any longer if class auto loader can not find the class.
+
+
+Affected Installations
+======================
+
+Instances using
+
+.. code-block:: php
+
+       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']
+       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck']
+
+
+Migration
+=========
+
+Make sure the hook classes are found with the casual auto loading mechanism
+that is also used for all other PHP classes. The hook registration can be
+simplified to an empty value, example:
+
+.. code-block:: php
+
+       $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\TYPO3\CMS\Saltedpasswords\Evaluation\FrontendEvaluator::class] = '';
+
index 68f69eb..56227c0 100644 (file)
@@ -2,9 +2,9 @@
 defined('TYPO3_MODE') or die();
 
 // Form evaluation function for fe_users
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']['TYPO3\\CMS\\Saltedpasswords\\Evaluation\\FrontendEvaluator'] = 'EXT:saltedpasswords/Classes/Evaluation/FrontendEvaluator.php';
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\TYPO3\CMS\Saltedpasswords\Evaluation\FrontendEvaluator::class] = '';
 // Form evaluation function for be_users
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']['TYPO3\\CMS\\Saltedpasswords\\Evaluation\\BackendEvaluator'] = 'EXT:saltedpasswords/Classes/Evaluation/BackendEvaluator.php';
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\TYPO3\CMS\Saltedpasswords\Evaluation\BackendEvaluator::class] = '';
 
 // Hook for processing "forgotPassword" in felogin
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::class . '->feloginForgotPasswordHook';
index a01a0e7..32522bc 100644 (file)
@@ -755,11 +755,15 @@ class SetupModuleController {
         */
        protected function checkAccess(array $config) {
                $access = $config['access'];
-               // Check for hook
-               $accessObject = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
-               if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck')) {
-                       // Initialize vars. If method fails, $set will be set to FALSE
-                       return $accessObject->accessLevelCheck($config);
+
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access])) {
+                       if (class_exists($access)) {
+                               $accessObject = GeneralUtility::makeInstance($access);
+                               if (method_exists($accessObject, 'accessLevelCheck')) {
+                                       // Initialize vars. If method fails, $set will be set to FALSE
+                                       return $accessObject->accessLevelCheck($config);
+                               }
+                       }
                } elseif ($access == 'admin') {
                        return $this->isAdmin;
                }