PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.5
GiveWP – Donation Plugin and Fundraising Platform v4.15.5
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / FieldsAPI / Actions / CreateValidatorFromForm.php

CreateValidatorFromForm.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.5, at src/Framework/FieldsAPI/Actions/CreateValidatorFromForm.php

34 lines 828 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Give\Framework\FieldsAPI\Actions;
6
7 use Give\Framework\FieldsAPI\Form;
8 use Give\Vendors\StellarWP\Validation\Validator;
9
10 class CreateValidatorFromForm
11 {
12 /**
13 * @since 3.0.0 Update validation rules with optional as default.
14 * @since 2.24.0
15 */
16 public function __invoke(Form $form, array $values): Validator
17 {
18 $labels = [];
19 $rules = [];
20
21 foreach ($form->getFields() as $field) {
22 $rules[$field->getName()] = (new UpdateValidationRulesWithOptionalAsDefault())(
23 $field->getValidationRules()
24 );
25
26 if (method_exists($field, 'getLabel')) {
27 $labels[$field->getName()] = $field->getLabel();
28 }
29 }
30
31 return new Validator($rules, $values, $labels);
32 }
33 }
34