TYPO3 CMS  TYPO3_6-2
AbstractValidator.php
Go to the documentation of this file.
1 <?php
3 
23 
29  protected $fieldName;
30 
39  protected $message = array();
40 
49  protected $error = array();
50 
56  protected $showMessage = TRUE;
57 
64 
70  protected $requestHandler;
71 
77  protected $localCobj;
78 
85  public function injectRequestHandler(\TYPO3\CMS\Form\Request $requestHandler) {
86  $this->requestHandler = $requestHandler;
87  }
88 
94  public function __construct($arguments) {
95  $this->localCobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
96  $this->injectRequestHandler(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request'));
97  $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
98  $this->setFieldName($arguments['element']);
99  $this->setMessage($arguments['message.'], $arguments['message']);
100  $this->setShowMessage($arguments['showMessage']);
101  $this->setError($arguments['error.'], $arguments['error']);
102  }
103 
110  public function setFieldName($fieldName) {
111  $this->fieldName = (string) $fieldName;
112  return $this;
113  }
114 
120  public function getFieldName() {
121  return $this->fieldName;
122  }
123 
129  public function getMessage() {
130  return $this->message;
131  }
132 
138  public function getError() {
139  return $this->error;
140  }
141 
156  public function setMessage($message = '', $type = 'TEXT') {
157  if (empty($message)) {
158  if (!empty($type)) {
159  $message = $type;
160  $type = 'TEXT';
161  } else {
162  $type = 'TEXT';
163  $message = $this->getLocalLanguageLabel('message');
164  }
165  $value['value'] = $this->substituteValues($message);
166  } elseif (!is_array($message)) {
167  $value['value'] = $this->substituteValues($message);
168  } else {
169  $value = $message;
170  }
171  $this->message['cObj'] = (string) $type;
172  $this->message['cObj.'] = $value;
173  }
174 
188  public function setError($error = '', $type = 'TEXT') {
189  if (empty($error)) {
190  if (!empty($type)) {
191  $error = $type;
192  $type = 'TEXT';
193  } else {
194  $type = 'TEXT';
195  $error = $this->getLocalLanguageLabel('error');
196  }
197  $value['value'] = $this->substituteValues($error);
198  } elseif (!is_array($error)) {
199  $value['value'] = $this->substituteValues($error);
200  } else {
201  $value = $error;
202  }
203  $this->error['cObj'] = (string) $type;
204  $this->error['cObj.'] = $value;
205  }
206 
213  public function setShowMessage($show) {
214  if ($show === NULL) {
215  $this->showMessage = TRUE;
216  } else {
217  $this->showMessage = (bool) $show;
218  }
219  return $this;
220  }
221 
227  public function messageMustBeDisplayed() {
228  return $this->showMessage;
229  }
230 
238  protected function substituteValues($message) {
239  return $message;
240  }
241 
249  protected function getLocalLanguageLabel($type) {
250  $label = static::LOCALISATION_OBJECT_NAME . '.' . $type;
251  $message = $this->localizationHandler->getLocalLanguageLabel($label);
252  return $message;
253  }
254 
255 }
injectRequestHandler(\TYPO3\CMS\Form\Request $requestHandler)