[TASK] Catch exceptions in itemsProcFunc 86/24786/5
authorFrancois Suter <francois@typo3.org>
Tue, 15 Oct 2013 09:06:45 +0000 (11:06 +0200)
committerFrancois Suter <francois@typo3.org>
Wed, 6 Nov 2013 16:12:39 +0000 (17:12 +0100)
It may be helpful to let itemsProcFuncs for field (e.g. select, check
and radio types) throw exceptions that are caught and displayed
properly as error message.

Actually https://review.typo3.org/#/c/24066/ introduces such an
exception.

Releases: 6.2
Resolves: #52836
Documentation: #52839
Change-Id: Icabdc528668844d5713142f0aad2d3923742dd11
Reviewed-on: https://review.typo3.org/24786
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Peter Foerger
Tested-by: Peter Foerger
Reviewed-by: Francois Suter
Tested-by: Francois Suter
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/lang/locallang_core.xlf

index daa35d4..fadf0ad 100644 (file)
@@ -4678,7 +4678,34 @@ function ' . $evalData . '(value) {
                $params['table'] = $table;
                $params['row'] = $row;
                $params['field'] = $field;
-               GeneralUtility::callUserFunction($config['itemsProcFunc'], $params, $this);
+               // The itemsProcFunc method may throw an exception.
+               // If it does display an error message and return items unchanged.
+               try {
+                       GeneralUtility::callUserFunction($config['itemsProcFunc'], $params, $this);
+               } catch (\Exception $exception) {
+                       $fieldLabel = $field;
+                       if (isset($GLOBALS['TCA'][$table]['columns'][$field]['label'])) {
+                               $fieldLabel = $this->sL($GLOBALS['TCA'][$table]['columns'][$field]['label']);
+                       }
+                       $message = sprintf(
+                               $this->sL('LLL:EXT:lang/locallang_core.xlf:error.items_proc_func_error'),
+                               $fieldLabel,
+                               $exception->getMessage()
+                       );
+                       /** @var $flashMessage FlashMessage */
+                       $flashMessage = GeneralUtility::makeInstance(
+                               'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
+                               htmlspecialchars($message),
+                               '',
+                               FlashMessage::ERROR,
+                               TRUE
+                       );
+                       $class = 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService';
+                       /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
+                       $flashMessageService = GeneralUtility::makeInstance($class);
+                       $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+                       $defaultFlashMessageQueue->enqueue($flashMessage);
+               }
                return $items;
        }
 
index e4821f0..d18d9da 100644 (file)
@@ -996,6 +996,9 @@ Check also the following points:\n
                        <trans-unit id="error.database_schema_mismatch_title" xml:space="preserve">
                                <source>Database Error</source>
                        </trans-unit>
+                       <trans-unit id="error.items_proc_func_error" xml:space="preserve">
+                               <source>An error occurred trying to process items for field "%1$s" (%2$s).</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>