[BUGFIX] Form localization depending on old class names
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Confirmation / ConfirmationView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Confirmation;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Form\Domain\Model\Form;
19
20 /**
21 * Main view layer for Forms.
22 *
23 * @author Patrick Broens <patrick@patrickbroens.nl>
24 */
25 class ConfirmationView extends \TYPO3\CMS\Form\View\Confirmation\Element\ContainerElementView {
26
27 /**
28 * Constant for localisation
29 *
30 * @var string
31 */
32 const LOCALISATION_OBJECT_NAME = 'tx_form_view_confirmation';
33
34 /**
35 * Default layout of this object
36 *
37 * @var string
38 */
39 protected $layout = '
40 <containerWrap />';
41
42 /**
43 * The TypoScript settings for the confirmation
44 *
45 * @var array
46 */
47 protected $typoscript = array();
48
49 /**
50 * The localization handler
51 *
52 * @var \TYPO3\CMS\Form\Localization
53 */
54 protected $localizationHandler;
55
56 /**
57 * The content object
58 *
59 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
60 */
61 protected $localCobj;
62
63 /**
64 * Constructor
65 *
66 * @param Form $model
67 * @param array $typoscript
68 */
69 public function __construct(Form $model, array $typoscript) {
70 $this->localCobj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
71 $this->localizationHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Localization::class);
72 $this->typoscript = $typoscript;
73 parent::__construct($model);
74 }
75
76 /**
77 * Set the data for the FORM tag
78 *
79 * @param Form $model The model of the form
80 * @return void
81 */
82 public function setData(Form $model) {
83 $this->model = (object) $model;
84 }
85
86 /**
87 * Start the main DOMdocument for the form
88 * Return it as a string using saveXML() to get a proper formatted output
89 * (when using formatOutput :-)
90 *
91 * @return string XHTML string containing the whole form
92 */
93 public function get() {
94 $message = $this->getMessage();
95 $node = $this->render('element', FALSE);
96 if ($node !== NULL) {
97 $formInput = LF . html_entity_decode($node->saveXML($node->firstChild), ENT_QUOTES, 'UTF-8') . LF;
98 } else {
99 $formInput = '';
100 }
101 $confirmationButtons = $this->getConfirmationButtons();
102 $content = $message . LF . $formInput . LF . $confirmationButtons;
103 return $content;
104 }
105
106 /**
107 * Construct the message
108 *
109 * The message is a cObj, which can be overriden using the typoscript
110 * setting confirmation.message, like
111 *
112 * confirmation.message = TEXT
113 * confirmation.message.value = Here some text
114 * confirmation.message.wrap = <p>|</p>
115 *
116 * @return string XHTML string containing the message
117 */
118 protected function getMessage() {
119 if (isset($this->typoscript['message']) && isset($this->typoscript['message.'])) {
120 $value = $this->typoscript['message.'];
121 $type = $this->typoscript['message'];
122 } elseif (isset($this->typoscript['message.'])) {
123 $value = $this->typoscript['message.'];
124 $type = 'TEXT';
125 } else {
126 $value['wrap'] = '<p>|</p>';
127 $value['value'] = $this->getLocalLanguageLabel('message');
128 $type = 'TEXT';
129 }
130 return $this->localCobj->cObjGetSingle($type, $value);
131 }
132
133 /**
134 * Get confirmation buttons
135 *
136 * @return string
137 */
138 protected function getConfirmationButtons() {
139 $requestHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Request::class);
140 $prefix = $requestHandler->getPrefix();
141 $action = $this->localCobj->getTypoLink_URL($GLOBALS['TSFE']->id);
142 $confirmationButtons = '
143 <form class="csc-form-confirmation" method="post" action="' . $action . '">
144 <fieldset>
145 <ol>
146 <li class="csc-form-confirmation-false">
147 <input type="submit" value="' . $this->getLocalLanguageLabel('donotconfirm') . '" name="' . $prefix . '[confirmation-false]" />
148 </li>
149 <li class="csc-form-confirmation-true">
150 <input type="submit" value="' . $this->getLocalLanguageLabel('confirm') . '" name="' . $prefix . '[confirmation-true]" />
151 </li>
152 </ol>
153 </fieldset>
154 </form>
155 ';
156 return $confirmationButtons;
157 }
158
159 /**
160 * Get the local language label(s) for the message
161 *
162 * @param string $type The type
163 * @return string The local language message label
164 */
165 protected function getLocalLanguageLabel($type) {
166 $label = self::LOCALISATION_OBJECT_NAME . '.' . $type;
167 $message = $this->localizationHandler->getLocalLanguageLabel($label);
168 return $message;
169 }
170
171 }