‪TYPO3CMS  ‪main
ItemProcessingService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 
30 {
42  public function ‪getProcessingItems($table, $realPid, $field, $row, $tcaConfig, $selectedItems)
43  {
44  $pageId = (int)($table === 'pages' ? ($row['uid'] ?? $realPid) : ($row['pid'] ?? $realPid));
45  $TSconfig = BackendUtility::getPagesTSconfig($pageId);
46  $fieldTSconfig = $TSconfig['TCEFORM.'][$table . '.'][$field . '.'] ?? [];
47 
48  $params = [];
49  $params['items'] = &$selectedItems;
50  $params['config'] = $tcaConfig;
51  $params['TSconfig'] = $fieldTSconfig['itemsProcFunc.'] ?? null;
52  $params['table'] = $table;
53  $params['row'] = $row;
54  $params['field'] = $field;
55 
56  // The itemsProcFunc method may throw an exception.
57  // If it does, display an error message and return items unchanged.
58  try {
59  $params['items'] = array_map(
60  fn(array $item) => ‪SelectItem::fromTcaItemArray($item, $params['config']['type']),
61  $params['items']
62  );
63  GeneralUtility::callUserFunction($tcaConfig['itemsProcFunc'], $params, $this);
64  $params['items'] = array_map(
65  fn($item) => $item instanceof ‪SelectItem ? $item : ‪SelectItem::fromTcaItemArray($item, $params['config']['type']),
66  $params['items']
67  );
68  } catch (\‪Exception $exception) {
69  $languageService = $this->‪getLanguageService();
70  $fieldLabel = $field;
71  if (isset(‪$GLOBALS['TCA'][$table]['columns'][$field]['label'])) {
72  $fieldLabel = $languageService->sL(‪$GLOBALS['TCA'][$table]['columns'][$field]['label']);
73  }
74  $message = sprintf(
75  $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:error.items_proc_func_error'),
76  $fieldLabel,
77  $exception->getMessage()
78  );
79  $flashMessage = GeneralUtility::makeInstance(
80  FlashMessage::class,
81  $message,
82  '',
83  ContextualFeedbackSeverity::ERROR,
84  true
85  );
86  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
87  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
88  $defaultFlashMessageQueue->enqueue($flashMessage);
89  }
90 
91  return $selectedItems;
92  }
93 
95  {
96  return ‪$GLOBALS['LANG'];
97  }
98 }
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:16
‪TYPO3\CMS\Core\DataHandling\ItemProcessingService\getLanguageService
‪getLanguageService()
Definition: ItemProcessingService.php:94
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Schema\Struct\SelectItem
Definition: SelectItem.php:21
‪TYPO3\CMS\Core\Schema\Struct\SelectItem\fromTcaItemArray
‪static fromTcaItemArray(array $item, string $type='select')
Definition: SelectItem.php:45
‪TYPO3\CMS\Core\DataHandling\ItemProcessingService
Definition: ItemProcessingService.php:30
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\DataHandling\ItemProcessingService\getProcessingItems
‪array getProcessingItems($table, $realPid, $field, $row, $tcaConfig, $selectedItems)
Definition: ItemProcessingService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27