‪TYPO3CMS  ‪main
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 
34 
40 {
41  private const ‪L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
42 
44  {
45  $row = $item->‪getRecord();
46  $itemContent = $this->‪linkEditContent('<strong>' . htmlspecialchars($item->‪getContext()->getContentTypeLabels()['form_formframework']) . '</strong>', $row) . '<br />';
47 
48  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
49  ->convertFlexFormContentToArray($row['pi_flexform']);
50 
51  $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'] ?? '';
52  if (!empty($persistenceIdentifier)) {
53  try {
54  $formPersistenceManager = GeneralUtility::makeInstance(FormPersistenceManagerInterface::class);
55 
56  try {
57  if (
58  $formPersistenceManager->hasValidFileExtension($persistenceIdentifier)
59  || ‪PathUtility::isExtensionPath($persistenceIdentifier)
60  ) {
61  $formDefinition = $formPersistenceManager->load($persistenceIdentifier);
62  $formLabel = $formDefinition['label'];
63  } else {
64  $formLabel = sprintf(
65  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
66  $persistenceIdentifier
67  );
68  }
69  } catch (‪ParseErrorException $e) {
70  $formLabel = sprintf(
71  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
72  $persistenceIdentifier
73  );
74  } catch (‪PersistenceManagerException $e) {
75  $formLabel = sprintf(
76  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
77  $persistenceIdentifier
78  );
79  } catch (‪Exception $e) {
80  $formLabel = sprintf(
81  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
82  $persistenceIdentifier
83  );
84  }
85  } catch (‪NoSuchFileException $e) {
86  $this->‪addInvalidFrameworkConfigurationFlashMessage($persistenceIdentifier, $e);
87  $formLabel = sprintf(
88  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
89  $persistenceIdentifier
90  );
91  } catch (‪ParseErrorException $e) {
92  $this->‪addInvalidFrameworkConfigurationFlashMessage($persistenceIdentifier, $e);
93  $formLabel = sprintf(
94  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
95  $persistenceIdentifier
96  );
97  } catch (\‪Exception $e) {
98  // Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
99  $this->‪addInvalidFrameworkConfigurationFlashMessage($persistenceIdentifier, $e);
100  $formLabel = sprintf(
101  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'),
102  $persistenceIdentifier,
103  $e->getMessage()
104  );
105  }
106  } else {
107  $formLabel = $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
108  }
109 
110  $itemContent .= $this->‪linkEditContent(
111  htmlspecialchars($formLabel),
112  $row
113  ) . '<br />';
114 
115  return $itemContent;
116  }
117 
118  protected function ‪addInvalidFrameworkConfigurationFlashMessage(string $persistenceIdentifier, \‪Exception $e): void
119  {
120  $messageText = sprintf(
121  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'),
122  $persistenceIdentifier,
123  $e->getMessage()
124  );
125 
126  GeneralUtility::makeInstance(FlashMessageService::class)
127  ->getMessageQueueByIdentifier('core.template.flashMessages')
128  ->enqueue(
129  GeneralUtility::makeInstance(
130  FlashMessage::class,
131  $messageText,
132  $this->‪getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.title'),
133  ContextualFeedbackSeverity::ERROR,
134  true
135  )
136  );
137  }
138 
140  {
141  return ‪$GLOBALS['LANG'];
142  }
143 }
‪TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer
Definition: StandardContentPreviewRenderer.php:49
‪TYPO3\CMS\Core\Utility\PathUtility\isExtensionPath
‪static isExtensionPath(string $path)
Definition: PathUtility.php:117
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\addInvalidFrameworkConfigurationFlashMessage
‪addInvalidFrameworkConfigurationFlashMessage(string $persistenceIdentifier, \Exception $e)
Definition: FormPagePreviewRenderer.php:118
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\AbstractGridObject\getContext
‪getContext()
Definition: AbstractGridObject.php:54
‪TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException
Definition: PersistenceManagerException.php:27
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\L10N_PREFIX
‪const L10N_PREFIX
Definition: FormPagePreviewRenderer.php:41
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem\getRecord
‪getRecord()
Definition: GridColumnItem.php:203
‪TYPO3\CMS\Form\Hooks
Definition: FormElementHooks.php:16
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\getLanguageService
‪getLanguageService()
Definition: FormPagePreviewRenderer.php:139
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer
Definition: FormPagePreviewRenderer.php:40
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException
Definition: ParseErrorException.php:24
‪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\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer\linkEditContent
‪string linkEditContent(string $linkText, $row)
Definition: StandardContentPreviewRenderer.php:361
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:45
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer\renderPageModulePreviewContent
‪renderPageModulePreviewContent(GridColumnItem $item)
Definition: FormPagePreviewRenderer.php:43
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException
Definition: NoSuchFileException.php:24