2 namespace TYPO3\CMS\Form\Validation
;
4 /***************************************************************
7 * (c) 2008 Patrick Broens (patrick@patrickbroens.nl)
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
29 * @author Patrick Broens <patrick@patrickbroens.nl>
33 class AlphabeticValidator
extends \TYPO3\CMS\Form\Validation\AbstractValidator
{
36 * Allow white space in the submitted value
40 protected $allowWhiteSpace;
43 * Alphabetic filter used for validation
45 * @var tx_form_Filter_Alphabetic
52 * @param array $arguments Typoscript configuration
55 public function __construct($arguments = array()) {
56 $this->setAllowWhiteSpace($arguments['allowWhiteSpace']);
57 parent
::__construct($arguments);
61 * Returns TRUE if submitted value validates according to rule
64 * @see tx_form_System_Validate_Interface::isValid()
66 public function isValid() {
67 if ($this->requestHandler
->has($this->fieldName
)) {
68 $value = $this->requestHandler
->getByMethod($this->fieldName
);
69 if ($this->filter
=== NULL) {
70 $className = 'TYPO3\\CMS\\Form\\Filter\\AlphabeticFilter';
71 $this->filter
= \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance($className);
73 $this->filter
->setAllowWhiteSpace($this->allowWhiteSpace
);
74 if ($this->filter
->filter($value) !== $value) {
82 * Set TRUE if white space is allowed in submitted value
84 * @param boolean $allowWhiteSpace TRUE if white space allowed
85 * @return object Rule object
87 public function setAllowWhiteSpace($allowWhiteSpace) {
88 if ($allowWhiteSpace === NULL) {
89 $this->allowWhiteSpace
= FALSE;
91 $this->allowWhiteSpace
= (bool) $allowWhiteSpace;
97 * Get the local language label(s) for the message
98 * Overrides the abstract
100 * @return string The local language message label
101 * @see tx_form_System_Validate_Abstract::_getLocalLanguageLabel()
103 protected function getLocalLanguageLabel() {
104 $label = strtolower(get_class($this)) . '.message';
105 $messages[] = $this->localizationHandler
->getLocalLanguageLabel($label);
106 if ($this->allowWhiteSpace
) {
107 $messages[] = $this->localizationHandler
->getLocalLanguageLabel($label . '2');
109 $message = implode(', ', $messages);