TYPO3  7.6
RequiredValidator.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Domain\Validator;
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 {
24  const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate_required';
25 
29  protected $allFieldsAreEmpty = true;
30 
38  public function isValid($value)
39  {
40  if (is_array($value)) {
41  array_walk_recursive($value, function ($value, $key, $validator) {
42  if (!empty($value) || $value === '0' || $value === 0) {
43  $validator->setAllFieldsAreEmpty(false);
44  }
45  },
46  $this
47  );
48  if ($this->getAllFieldsAreEmpty()) {
49  $this->addError(
50  $this->renderMessage(
51  $this->options['errorMessage'][0],
52  $this->options['errorMessage'][1],
53  'error'
54  ),
55  1441980673
56  );
57  }
58  } else {
59  if (
60  empty($value)
61  && $value !== 0
62  && $value !== '0'
63  ) {
64  $this->addError(
65  $this->renderMessage(
66  $this->options['errorMessage'][0],
67  $this->options['errorMessage'][1],
68  'error'
69  ),
70  144198067
71  );
72  }
73  }
74  }
75 
85  protected function setAllFieldsAreEmpty($allFieldsAreEmpty = true)
86  {
87  $this->allFieldsAreEmpty = $allFieldsAreEmpty;
88  }
89 
98  protected function getAllFieldsAreEmpty()
99  {
101  }
102 }