TYPO3 CMS  TYPO3_7-6
BetweenValidator.php
Go to the documentation of this file.
1 <?php
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 
18 {
22  protected $supportedOptions = [
23  'element' => ['', 'The name of the element', 'string', true],
24  'errorMessage' => ['', 'The error message', 'array', true],
25  'minimum' => ['', 'The minimum value', 'integer', true],
26  'maximum' => ['', 'The maximum value', 'integer', true],
27  'inclusive' => ['', 'Minimum and maximum value are inclusive in comparison', 'integer', false],
28  ];
29 
35  const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_between';
36 
44  public function isValid($value)
45  {
46  if (
47  !isset($this->options['inclusive'])
48  || $this->options['inclusive'] === ''
49  || (int)$this->options['inclusive'] === 0
50  ) {
51  if ($value <= $this->options['minimum'] || $value >= $this->options['maximum']) {
52  $this->addError(
53  $this->renderMessage(
54  $this->options['errorMessage'][0],
55  $this->options['errorMessage'][1],
56  'error'
57  ),
58  1442003544
59  );
60  }
61  } else {
62  if ($value < $this->options['minimum'] || $value > $this->options['maximum']) {
63  $this->addError(
64  $this->renderMessage(
65  $this->options['errorMessage'][0],
66  $this->options['errorMessage'][1],
67  'error'
68  ),
69  1442003545
70  );
71  }
72  }
73  }
74 
83  public function getLocalLanguageLabel($type = '')
84  {
85  $label = static::LOCALISATION_OBJECT_NAME . '.' . $type;
87  if ($this->inclusive) {
88  $messages[] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($label . 2, 'form');
89  }
90  $message = implode(', ', $messages);
91  return $message;
92  }
93 
101  public function substituteMarkers($message)
102  {
103  return str_replace(
104  ['%minimum', '%maximum'],
105  [$this->options['minimum'], $this->options['maximum']],
106  $message
107  );
108  }
109 }
static translate($key, $extensionName, $arguments=null)
addError($message, $code, array $arguments=[], $title='')
renderMessage($message=null, $type=null, $messageType='message')