DeprecateOldTemplateHook.php
4 years ago
HookCommandInterface.php
5 years ago
SetupFieldConfirmation.php
4 years ago
SetupFieldEmailTag.php
4 years ago
SetupFieldPersistance.php
4 years ago
SetupFieldReceipt.php
4 years ago
SetupFieldValidation.php
4 years ago
SetupNewTemplateHook.php
4 years ago
SetupFieldValidation.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Form\LegacyConsumer\Commands; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Field; |
| 6 | use Give\Framework\FieldsAPI\Group; |
| 7 | |
| 8 | /** |
| 9 | * Setup field validation for custom fields on the required fields hook. |
| 10 | * |
| 11 | * @NOTE This is reducing on required fields, so it doesn't implement the shared interface. This is a special case. |
| 12 | * |
| 13 | * @since 2.10.2 |
| 14 | */ |
| 15 | class SetupFieldValidation { |
| 16 | |
| 17 | /** |
| 18 | * @since 2.10.2 |
| 19 | * |
| 20 | * @param int $formID |
| 21 | */ |
| 22 | public function __construct( $formID ) { |
| 23 | $this->formID = $formID; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @since 2.10.2 |
| 28 | * |
| 29 | * @param Field[] $requiredFields |
| 30 | * @param string $hook |
| 31 | * |
| 32 | * @return array |
| 33 | */ |
| 34 | public function __invoke( $requiredFields, $hook ) { |
| 35 | $collection = Group::make( $hook ); |
| 36 | do_action( "give_fields_$hook", $collection, $this->formID ); |
| 37 | $collection->walkFields( |
| 38 | function( $field ) use ( &$requiredFields ) { |
| 39 | if ( $field->isRequired() ) { |
| 40 | $requiredFields[ $field->getName() ] = $field->getRequiredError(); |
| 41 | } |
| 42 | } |
| 43 | ); |
| 44 | return $requiredFields; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 |