‪TYPO3CMS  10.4
FormPagePreviewRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 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 
18 namespace ‪TYPO3\CMS\Form\Hooks;
19 
36 
42 {
46  const ‪L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
47 
57  public function ‪preProcess(
58  ‪PageLayoutView &$parentObject,
59  &$drawItem,
60  &$headerContent,
61  &$itemContent,
62  array &$row
63  ) {
64  if ($row['CType'] === 'form_formframework') {
65  $contentType = $parentObject->CType_labels[$row['CType']];
66  $itemContent .= $parentObject->‪linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
67 
68  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
69  ->convertFlexFormContentToArray($row['pi_flexform']);
70 
71  $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
72  if (!empty($persistenceIdentifier)) {
73  try {
74  $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
75 
76  try {
77  if (
79  || strpos($persistenceIdentifier, 'EXT:') === 0
80  ) {
81  $formDefinition = $formPersistenceManager->load($persistenceIdentifier);
82  $formLabel = $formDefinition['label'];
83  } else {
84  $formLabel = sprintf(
85  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
86  $persistenceIdentifier
87  );
88  }
89  } catch (‪ParseErrorException $e) {
90  $formLabel = sprintf(
91  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
92  $persistenceIdentifier
93  );
94  } catch (‪PersistenceManagerException $e) {
95  $formLabel = sprintf(
96  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
97  $persistenceIdentifier
98  );
99  } catch (‪Exception $e) {
100  $formLabel = sprintf(
101  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
102  $persistenceIdentifier
103  );
104  }
105  } catch (‪NoSuchFileException $e) {
107  $formLabel = sprintf(
108  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
109  $persistenceIdentifier
110  );
111  } catch (‪ParseErrorException $e) {
113  $formLabel = sprintf(
114  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
115  $persistenceIdentifier
116  );
117  } catch (\‪Exception $e) {
118  // Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
120  $formLabel = $e->getMessage();
121  }
122  } else {
123  $formLabel = $this->‪getLanguageService()->‪sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
124  }
125 
126  $itemContent .= $parentObject->‪linkEditContent(
127  $parentObject->‪renderText($formLabel),
128  $row
129  ) . '<br />';
130 
131  $drawItem = false;
132  }
133  }
134 
139  {
140  $messageText = sprintf(
141  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'),
142  $e->getMessage()
143  );
144 
145  GeneralUtility::makeInstance(FlashMessageService::class)
146  ->getMessageQueueByIdentifier('core.template.flashMessages')
147  ->enqueue(
148  GeneralUtility::makeInstance(
149  FlashMessage::class,
150  $messageText,
151  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.title'),
153  true
154  )
155  );
156  }
157 
162  {
163  return ‪$GLOBALS['LANG'];
164  }
165 }
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Utility\StringUtility\endsWith
‪static bool endsWith($haystack, $needle)
Definition: StringUtility.php:61
‪TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
Definition: PageLayoutViewDrawItemHookInterface.php:23
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException
Definition: PersistenceManagerException.php:28
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\L10N_PREFIX
‪const L10N_PREFIX
Definition: FormPagePreviewRenderer.php:46
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\preProcess
‪preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
Definition: FormPagePreviewRenderer.php:57
‪TYPO3\CMS\Form\Hooks
Definition: DataStructureIdentifierHook.php:18
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
Definition: FormPersistenceManager.php:54
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Backend\View\PageLayoutView\renderText
‪string renderText($input)
Definition: PageLayoutView.php:1693
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\getLanguageService
‪LanguageService getLanguageService()
Definition: FormPagePreviewRenderer.php:161
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer
Definition: FormPagePreviewRenderer.php:42
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException
Definition: ParseErrorException.php:25
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\View\PageLayoutView
Definition: PageLayoutView.php:61
‪TYPO3\CMS\Backend\View\PageLayoutView\linkEditContent
‪string linkEditContent($str, $row)
Definition: PageLayoutView.php:1517
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\addInvalidFrameworkConfigurationFlashMessage
‪addInvalidFrameworkConfigurationFlashMessage(\Exception $e)
Definition: FormPagePreviewRenderer.php:138
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager\FORM_DEFINITION_FILE_EXTENSION
‪const FORM_DEFINITION_FILE_EXTENSION
Definition: FormPersistenceManager.php:55
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException
Definition: NoSuchFileException.php:25