‪TYPO3CMS  9.5
FormPagePreviewRenderer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
33 
39 {
43  const ‪L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
44 
54  public function ‪preProcess(
55  \‪TYPO3\CMS\Backend\View\PageLayoutView &$parentObject,
56  &$drawItem,
57  &$headerContent,
58  &$itemContent,
59  array &$row
60  ) {
61  if ($row['CType'] === 'form_formframework') {
62  $contentType = $parentObject->CType_labels[$row['CType']];
63  $itemContent .= $parentObject->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
64 
65  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
66  ->convertFlexFormContentToArray($row['pi_flexform']);
67 
68  $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
69  if (!empty($persistenceIdentifier)) {
70  try {
71  $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
72 
73  try {
74  if (
76  || strpos($persistenceIdentifier, 'EXT:') === 0
77  ) {
78  $formDefinition = $formPersistenceManager->load($persistenceIdentifier);
79  $formLabel = $formDefinition['label'];
80  } else {
81  $formLabel = sprintf(
82  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
83  $persistenceIdentifier
84  );
85  }
86  } catch (‪ParseErrorException $e) {
87  $formLabel = sprintf(
88  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
89  $persistenceIdentifier
90  );
91  } catch (‪PersistenceManagerException $e) {
92  $formLabel = sprintf(
93  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
94  $persistenceIdentifier
95  );
96  } catch (‪Exception $e) {
97  $formLabel = sprintf(
98  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
99  $persistenceIdentifier
100  );
101  }
102  } catch (‪NoSuchFileException $e) {
104  $formLabel = sprintf(
105  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
106  $persistenceIdentifier
107  );
108  } catch (‪ParseErrorException $e) {
110  $formLabel = sprintf(
111  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
112  $persistenceIdentifier
113  );
114  } catch (\‪Exception $e) {
115  // Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
117  $formLabel = $e->getMessage();
118  }
119  } else {
120  $formLabel = $this->‪getLanguageService()->‪sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
121  }
122 
123  $itemContent .= $parentObject->linkEditContent(
124  $parentObject->renderText($formLabel),
125  $row
126  ) . '<br />';
127 
128  $drawItem = false;
129  }
130  }
131 
136  {
137  $messageText = sprintf(
138  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'),
139  $e->getMessage()
140  );
141 
142  GeneralUtility::makeInstance(ObjectManager::class)
143  ->get(FlashMessageService::class)
144  ->getMessageQueueByIdentifier('core.template.flashMessages')
145  ->enqueue(
146  GeneralUtility::makeInstance(
147  FlashMessage::class,
148  $messageText,
149  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.title'),
151  true
152  )
153  );
154  }
155 
160  {
161  return ‪$GLOBALS['LANG'];
162  }
163 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:24
‪TYPO3\CMS\Core\Utility\StringUtility\endsWith
‪static bool endsWith($haystack, $needle)
Definition: StringUtility.php:60
‪TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
Definition: PageLayoutViewDrawItemHookInterface.php:22
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException
Definition: PersistenceManagerException.php:26
‪TYPO3
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\L10N_PREFIX
‪const L10N_PREFIX
Definition: FormPagePreviewRenderer.php:43
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:21
‪TYPO3\CMS\Form\Hooks
Definition: DataStructureIdentifierHook.php:3
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
Definition: FormPersistenceManager.php:48
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\getLanguageService
‪LanguageService getLanguageService()
Definition: FormPagePreviewRenderer.php:159
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer
Definition: FormPagePreviewRenderer.php:39
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException
Definition: ParseErrorException.php:24
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\addInvalidFrameworkConfigurationFlashMessage
‪addInvalidFrameworkConfigurationFlashMessage(\Exception $e)
Definition: FormPagePreviewRenderer.php:135
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\preProcess
‪preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
Definition: FormPagePreviewRenderer.php:54
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:28
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:21
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager\FORM_DEFINITION_FILE_EXTENSION
‪const FORM_DEFINITION_FILE_EXTENSION
Definition: FormPersistenceManager.php:49
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException
Definition: NoSuchFileException.php:24