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