TYPO3 CMS  TYPO3_7-6
AlphabeticValidator.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  'allowWhiteSpace' => ['', 'Whitespaces are allowed', 'boolean', false],
26  ];
27 
33  const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_alphabetic';
34 
42  public function isValid($value)
43  {
44  if (
45  !isset($this->options['allowWhiteSpace'])
46  || $this->options['allowWhiteSpace'] === ''
47  || (int)$this->options['allowWhiteSpace'] === 0
48  ) {
49  $this->options['allowWhiteSpace'] = false;
50  } else {
51  $this->options['allowWhiteSpace'] = true;
52  }
53 
54  $whiteSpace = $this->options['allowWhiteSpace'] ? '\\s' : '';
55  $pattern = '/[^\pL' . $whiteSpace . ']/u';
56  $compareValue = preg_replace($pattern, '', (string)$value);
57 
58  if ($compareValue !== $value) {
59  $this->addError(
60  $this->renderMessage(
61  $this->options['errorMessage'][0],
62  $this->options['errorMessage'][1],
63  'error'
64  ),
65  1442004245
66  );
67  }
68  }
69 
78  public function getLocalLanguageLabel($type = '')
79  {
80  $label = static::LOCALISATION_OBJECT_NAME . '.message';
82  if ($this->options['allowWhiteSpace']) {
83  $messages[] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($label . 2, 'form');
84  }
85  $message = implode(', ', $messages);
86  return $message;
87  }
88 }
static translate($key, $extensionName, $arguments=null)
addError($message, $code, array $arguments=[], $title='')
renderMessage($message=null, $type=null, $messageType='message')