← All changes
|
modules/validation/ssr/base-validation-callback.php
+16
-0
3.6.4
→
3.6.6
View file →
| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | |
| 6 | 6 | use Jet_Form_Builder\Classes\Arrayable\Arrayable; |
| 7 | 7 | use JFB_Components\Repository\Repository_Item_Instance_Trait; |
| 8 | 8 | use Jet_Form_Builder\Request\Parser_Context; |
| 9 | +use JFB_Modules\Block_Parsers\Field_Data_Parser; | |
| 9 | 10 | |
| 10 | 11 | // If this file is called directly, abort. |
| 11 | 12 | if ( ! defined( 'WPINC' ) ) { |
| 12 | 13 | die; |
| @@ -24,8 +25,23 @@ | ||
| 24 | 25 | * |
| 25 | 26 | * @return bool |
| 26 | 27 | */ |
| 27 | 28 | abstract public function is_valid( $value, Parser_Context $context ): bool; |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Validate a field with access to its parser metadata. | |
| 32 | + * | |
| 33 | + * Existing callbacks only need to implement is_valid(). Callbacks that need | |
| 34 | + * trusted parser metadata can override this method without changing the | |
| 35 | + * public callback contract. | |
| 36 | + * | |
| 37 | + * @param Field_Data_Parser $parser | |
| 38 | + * | |
| 39 | + * @return bool | |
| 40 | + */ | |
| 41 | + public function is_valid_with_parser( Field_Data_Parser $parser ): bool { | |
| 42 | + return $this->is_valid( $parser->get_value(), $parser->get_context() ); | |
| 43 | + } | |
| 28 | 44 | |
| 29 | 45 | public function to_array(): array { |
| 30 | 46 | return array( |
| 31 | 47 | 'value' => $this->get_id(), |