[FEATURE] Make CSS for sysext form configurable
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Confirmation / Confirmation.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Patrick Broens (patrick@patrickbroens.nl)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Main view layer for Forms.
27 *
28 * @author Patrick Broens <patrick@patrickbroens.nl>
29 * @package TYPO3
30 * @subpackage form
31 */
32 class tx_form_View_Confirmation extends tx_form_View_Confirmation_Element_Container {
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 tx_form_System_Localization
53 */
54 protected $localizationHandler;
55
56 /**
57 * The content object
58 *
59 * @var tslib_cObj
60 */
61 protected $localCobj;
62
63 /**
64 * Constructor
65 *
66 * @return void
67 */
68 public function __construct(tx_form_Domain_Model_Form $model, array $typoscript) {
69 $this->localCobj = t3lib_div::makeInstance('tslib_cObj');
70 $this->localizationHandler = t3lib_div::makeInstance(
71 'tx_form_System_Localization'
72 );
73 $this->typoscript = $typoscript;
74 parent::__construct($model);
75 }
76
77 /**
78 * Set the data for the FORM tag
79 *
80 * @param tx_form_Domain_Model_Form $formModel The model of the form
81 * @return void
82 */
83 public function setData(tx_form_Domain_Model_Form $model) {
84 $this->model = (object) $model;
85 }
86
87 /**
88 * Start the main DOMdocument for the form
89 * Return it as a string using saveXML() to get a proper formatted output
90 * (when using formatOutput :-)
91 *
92 * @return string XHTML string containing the whole form
93 */
94 public function get() {
95 $message = $this->getMessage();
96
97 $node = $this->render('element', FALSE);
98 $formInput = chr(10) .
99 html_entity_decode(
100 $node->saveXML($node->firstChild),
101 ENT_QUOTES,
102 'UTF-8'
103 ) .
104 chr(10);
105
106 $confirmationButtons = $this->getConfirmationButtons();
107
108 $content = $message . chr(10) . $formInput . chr(10) . $confirmationButtons;
109
110 return $content;
111 }
112
113 /**
114 * Construct the message
115 *
116 * The message is a cObj, which can be overriden using the typoscript
117 * setting confirmation.message, like
118 *
119 * confirmation.message = TEXT
120 * confirmation.message.value = Here some text
121 * confirmation.message.wrap = <p>|</p>
122 *
123 * @return string XHTML string containing the message
124 */
125 protected function getMessage() {
126 if (isset($this->typoscript['message']) && isset($this->typoscript['message.'])) {
127 $value = $this->typoscript['message.'];
128 $type = $this->typoscript['message'];
129 } elseif (isset($this->typoscript['message.'])) {
130 $value = $this->typoscript['message.'];
131 $type = 'TEXT';
132 } else {
133 $value['wrap'] = '<p>|</p>';
134 $value['value'] = $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.message');
135 $type = 'TEXT';
136 }
137
138 return $this->localCobj->cObjGetSingle($type, $value);
139 }
140
141 protected function getConfirmationButtons() {
142 $requestHandler = t3lib_div::makeInstance('tx_form_System_Request');
143 $prefix = $requestHandler->getPrefix();
144 $action = $this->localCobj->getTypoLink_URL($GLOBALS['TSFE']->id);
145
146 $confirmationButtons = '
147 <form class="csc-form-confirmation" method="post" action="' . $action . '">
148 <fieldset>
149 <ol>
150 <li class="csc-form-confirmation-false">
151 <input type="submit" value="' .
152 $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.donotconfirm') .
153 '" name="' . $prefix . '[confirmation-false]" />
154 </li>
155 <li class="csc-form-confirmation-true">
156 <input type="submit" value="' .
157 $this->localizationHandler->getLocalLanguageLabel('tx_form_view_confirmation.confirm') .
158 '" name="' . $prefix . '[confirmation-true]" />
159 </li>
160 </ol>
161 </fieldset>
162 </form>
163 ';
164
165 return $confirmationButtons;
166 }
167 }
168 ?>