[BUGFIX] Call LOCALISATION_OBJECT_NAME 'static'ally
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Validation / AlphanumericValidator.php
1 <?php
2 namespace TYPO3\CMS\Form\Validation;
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 /**
18 * Alphanumeric rule
19 *
20 * @author Patrick Broens <patrick@patrickbroens.nl>
21 */
22 class AlphanumericValidator extends \TYPO3\CMS\Form\Validation\AbstractValidator {
23
24 /**
25 * Constant for localisation
26 *
27 * @var string
28 */
29 const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_alphanumeric';
30
31 /**
32 * Allow white space in the submitted value
33 *
34 * @var boolean
35 */
36 protected $allowWhiteSpace;
37
38 /**
39 * Constructor
40 *
41 * @param array $arguments Typoscript configuration
42 */
43 public function __construct($arguments) {
44 $this->setAllowWhiteSpace($arguments['allowWhiteSpace']);
45 parent::__construct($arguments);
46 }
47
48 /**
49 * Returns TRUE if submitted value validates according to rule
50 *
51 * @return boolean
52 * @see \TYPO3\CMS\Form\Validation\ValidatorInterface::isValid()
53 */
54 public function isValid() {
55 if ($this->requestHandler->has($this->fieldName)) {
56 $value = $this->requestHandler->getByMethod($this->fieldName);
57 if ($this->filter === NULL) {
58 $className = 'TYPO3\\CMS\\Form\\Filter\\AlphanumericFilter';
59 $this->filter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
60 }
61 $this->filter->setAllowWhiteSpace($this->allowWhiteSpace);
62 if ($this->filter->filter($value) !== $value) {
63 return FALSE;
64 }
65 }
66 return TRUE;
67 }
68
69 /**
70 * Set TRUE if white space is allowed in submitted value
71 *
72 * @param boolean $allowWhiteSpace TRUE if white space allowed
73 * @return object Rule object
74 */
75 public function setAllowWhiteSpace($allowWhiteSpace) {
76 if ($allowWhiteSpace === NULL) {
77 $this->allowWhiteSpace = FALSE;
78 } else {
79 $this->allowWhiteSpace = (bool) $allowWhiteSpace;
80 }
81 return $this;
82 }
83
84 /**
85 * Get the local language label(s) for the message
86 * Overrides the abstract
87 *
88 * @return string The local language message label
89 * @see \TYPO3\CMS\Form\Validation\AbstractValidator::_getLocalLanguageLabel()
90 */
91 protected function getLocalLanguageLabel() {
92 $label = static::LOCALISATION_OBJECT_NAME . '.message';
93 $messages[] = $this->localizationHandler->getLocalLanguageLabel($label);
94 if ($this->allowWhiteSpace) {
95 $messages[] = $this->localizationHandler->getLocalLanguageLabel($label . '2');
96 }
97 $message = implode(', ', $messages);
98 return $message;
99 }
100
101 }