|
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
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer; |
|
21
|
|
|
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem; |
|
22
|
|
|
use TYPO3\CMS\Core\Error\Exception; |
|
23
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
24
|
|
|
use TYPO3\CMS\Core\Messaging\AbstractMessage; |
|
25
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
26
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageService; |
|
27
|
|
|
use TYPO3\CMS\Core\Service\FlexFormService; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
use TYPO3\CMS\Core\Utility\StringUtility; |
|
30
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
31
|
|
|
use TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException; |
|
32
|
|
|
use TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException; |
|
33
|
|
|
use TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException; |
|
34
|
|
|
use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager; |
|
35
|
|
|
use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Contains a preview rendering for the page module of CType="form_formframework" |
|
39
|
|
|
* @internal |
|
40
|
|
|
*/ |
|
41
|
|
|
class FormPagePreviewRenderer extends StandardContentPreviewRenderer |
|
42
|
|
|
{ |
|
43
|
|
|
private const L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:'; |
|
44
|
|
|
|
|
45
|
|
|
public function renderPageModulePreviewContent(GridColumnItem $item): string |
|
46
|
|
|
{ |
|
47
|
|
|
$row = $item->getRecord(); |
|
48
|
|
|
$itemContent = $this->linkEditContent('<strong>' . htmlspecialchars($item->getContext()->getContentTypeLabels()['form_formframework']) . '</strong>', $row) . '<br />'; |
|
49
|
|
|
|
|
50
|
|
|
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class) |
|
51
|
|
|
->convertFlexFormContentToArray($row['pi_flexform']); |
|
52
|
|
|
|
|
53
|
|
|
$persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier']; |
|
54
|
|
|
if (!empty($persistenceIdentifier)) { |
|
55
|
|
|
try { |
|
56
|
|
|
$formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class); |
|
57
|
|
|
|
|
58
|
|
|
try { |
|
59
|
|
|
if ( |
|
60
|
|
|
StringUtility::endsWith($persistenceIdentifier, FormPersistenceManager::FORM_DEFINITION_FILE_EXTENSION) |
|
61
|
|
|
|| strpos($persistenceIdentifier, 'EXT:') === 0 |
|
62
|
|
|
) { |
|
63
|
|
|
$formDefinition = $formPersistenceManager->load($persistenceIdentifier); |
|
64
|
|
|
$formLabel = $formDefinition['label']; |
|
65
|
|
|
} else { |
|
66
|
|
|
$formLabel = sprintf( |
|
67
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'), |
|
68
|
|
|
$persistenceIdentifier |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} catch (ParseErrorException $e) { |
|
72
|
|
|
$formLabel = sprintf( |
|
73
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'), |
|
74
|
|
|
$persistenceIdentifier |
|
75
|
|
|
); |
|
76
|
|
|
} catch (PersistenceManagerException $e) { |
|
77
|
|
|
$formLabel = sprintf( |
|
78
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'), |
|
79
|
|
|
$persistenceIdentifier |
|
80
|
|
|
); |
|
81
|
|
|
} catch (Exception $e) { |
|
82
|
|
|
$formLabel = sprintf( |
|
83
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'), |
|
84
|
|
|
$persistenceIdentifier |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} catch (NoSuchFileException $e) { |
|
88
|
|
|
$this->addInvalidFrameworkConfigurationFlashMessage($e); |
|
89
|
|
|
$formLabel = sprintf( |
|
90
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'), |
|
91
|
|
|
$persistenceIdentifier |
|
92
|
|
|
); |
|
93
|
|
|
} catch (ParseErrorException $e) { |
|
94
|
|
|
$this->addInvalidFrameworkConfigurationFlashMessage($e); |
|
95
|
|
|
$formLabel = sprintf( |
|
96
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'), |
|
97
|
|
|
$persistenceIdentifier |
|
98
|
|
|
); |
|
99
|
|
|
} catch (\Exception $e) { |
|
100
|
|
|
// Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver |
|
101
|
|
|
$this->addInvalidFrameworkConfigurationFlashMessage($e); |
|
102
|
|
|
$formLabel = $e->getMessage(); |
|
103
|
|
|
} |
|
104
|
|
|
} else { |
|
105
|
|
|
$formLabel = $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$itemContent .= $this->linkEditContent( |
|
109
|
|
|
htmlspecialchars($formLabel), |
|
110
|
|
|
$row |
|
111
|
|
|
) . '<br />'; |
|
112
|
|
|
|
|
113
|
|
|
return $itemContent; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param \Exception $e |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function addInvalidFrameworkConfigurationFlashMessage(\Exception $e) |
|
120
|
|
|
{ |
|
121
|
|
|
$messageText = sprintf( |
|
122
|
|
|
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration.text'), |
|
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
|
|
|
AbstractMessage::ERROR, |
|
134
|
|
|
true |
|
135
|
|
|
) |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return LanguageService |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function getLanguageService(): LanguageService |
|
143
|
|
|
{ |
|
144
|
|
|
return $GLOBALS['LANG']; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|