[BUGFIX] Remove superflouos encoding in error message
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / DataHandling / ItemProcessingService.php
1 <?php
2 namespace TYPO3\CMS\Core\DataHandling;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Messaging\FlashMessageService;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Lang\LanguageService;
22
23 /**
24 * Provides services around item processing
25 */
26 class ItemProcessingService {
27
28 /**
29 * Executes an itemsProcFunc if defined in TCA and returns the combined result (predefined + processed items)
30 *
31 * @param string $table
32 * @param int $pageId
33 * @param string $field
34 * @param array $row
35 * @param array $tcaConfig The TCA configuration of $field
36 * @param array $selectedItems The items already defined in the TCA configuration
37 * @return array The processed items (including the predefined items)
38 */
39 public function getProcessingItems($table, $pageId, $field, $row, $tcaConfig, $selectedItems) {
40 $pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
41 $TSconfig = BackendUtility::getPagesTSconfig($pageId);
42 $fieldTSconfig = $TSconfig['TCEFORM.'][$table . '.'][$field . '.'];
43
44 $params = [];
45 $params['items'] = &$selectedItems;
46 $params['config'] = $tcaConfig;
47 $params['TSconfig'] = $fieldTSconfig['itemsProcFunc.'];
48 $params['table'] = $table;
49 $params['row'] = $row;
50 $params['field'] = $field;
51
52 // The itemsProcFunc method may throw an exception.
53 // If it does display an error message and return items unchanged.
54 try {
55 GeneralUtility::callUserFunction($tcaConfig['itemsProcFunc'], $params, $this);
56 } catch (\Exception $exception) {
57 $languageService = $this->getLanguageService();
58 $fieldLabel = $field;
59 if (isset($GLOBALS['TCA'][$table]['columns'][$field]['label'])) {
60 $fieldLabel = $languageService->sL($GLOBALS['TCA'][$table]['columns'][$field]['label']);
61 }
62 $message = sprintf(
63 $languageService->sL('LLL:EXT:lang/locallang_core.xlf:error.items_proc_func_error'),
64 $fieldLabel,
65 $exception->getMessage()
66 );
67 /** @var FlashMessage $flashMessage */
68 $flashMessage = GeneralUtility::makeInstance(
69 FlashMessage::class,
70 $message,
71 '',
72 FlashMessage::ERROR,
73 TRUE
74 );
75 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
76 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
77 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
78 $defaultFlashMessageQueue->enqueue($flashMessage);
79 }
80
81 return $selectedItems;
82 }
83
84 /**
85 * @return LanguageService
86 */
87 protected function getLanguageService() {
88 return $GLOBALS['LANG'];
89 }
90
91 }