TYPO3 CMS  TYPO3_8-7
FormPagePreviewRenderer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Form\Hooks;
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 
38 {
42  const L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
43 
53  public function preProcess(
54  \TYPO3\CMS\Backend\View\PageLayoutView &$parentObject,
55  &$drawItem,
56  &$headerContent,
57  &$itemContent,
58  array &$row
59  ) {
60  if ($row['CType'] === 'form_formframework') {
61  $contentType = $parentObject->CType_labels[$row['CType']];
62  $itemContent .= $parentObject->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
63 
64  $flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
65  ->convertFlexFormContentToArray($row['pi_flexform']);
66 
67  $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
68  if (!empty($persistenceIdentifier)) {
69  try {
70  $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
71 
72  try {
73  if (
75  || strpos($persistenceIdentifier, 'EXT:') === 0
76  ) {
77  $formDefinition = $formPersistenceManager->load($persistenceIdentifier);
78  $formLabel = $formDefinition['label'];
79  } else {
80  $formLabel = sprintf(
81  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
82  $persistenceIdentifier
83  );
84  }
85  } catch (ParseErrorException $e) {
86  $formLabel = sprintf(
87  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
88  $persistenceIdentifier
89  );
90  } catch (PersistenceManagerException $e) {
91  $formLabel = sprintf(
92  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
93  $persistenceIdentifier
94  );
95  } catch (Exception $e) {
96  $formLabel = sprintf(
97  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
98  $persistenceIdentifier
99  );
100  }
101  } catch (NoSuchFileException $e) {
103  $formLabel = sprintf(
104  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
105  $persistenceIdentifier
106  );
107  } catch (ParseErrorException $e) {
109  $formLabel = sprintf(
110  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
111  $persistenceIdentifier
112  );
113  } catch (\Exception $e) {
114  // Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
116  $formLabel = $e->getMessage();
117  }
118  } else {
119  $formLabel = $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
120  }
121 
122  $itemContent .= $parentObject->linkEditContent(
123  $parentObject->renderText($formLabel),
124  $row
125  ) . '<br />';
126 
127  $drawItem = false;
128  }
129  }
130 
135  {
136  $messageText = sprintf(
137  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'),
138  $e->getMessage()
139  );
140 
141  GeneralUtility::makeInstance(ObjectManager::class)
142  ->get(FlashMessageService::class)
143  ->getMessageQueueByIdentifier('core.template.flashMessages')
144  ->enqueue(
146  FlashMessage::class,
147  $messageText,
148  $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.title'),
150  true
151  )
152  );
153  }
154 
158  protected function getLanguageService(): LanguageService
159  {
160  return $GLOBALS['LANG'];
161  }
162 }
preProcess(\TYPO3\CMS\Backend\View\PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static endsWith($haystack, $needle)