| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | use JFB_Components\Module\Base_Module_It; |
| 16 | 16 | use JFB_Components\Module\Base_Module_Url_It; |
| 17 | 17 | use JFB_Components\Module\Base_Module_Url_Trait; |
| 18 | 18 | use JFB_Modules\Block_Parsers\Field_Data_Parser; |
| 19 | -use JFB_Modules\Validation\Messages; | |
| 20 | 19 | |
| 21 | 20 | // If this file is called directly, abort. |
| 22 | 21 | if ( ! defined( 'WPINC' ) ) { |
| 23 | 22 | die; |
| @@ -55,28 +54,8 @@ | ||
| 55 | 54 | /** |
| 56 | 55 | * @throws Repository_Exception |
| 57 | 56 | */ |
| 58 | 57 | public function on_install() { |
| 59 | - $this->rules = new Rules_Controller(); | |
| 60 | - $this->messages = apply_filters( | |
| 61 | - 'jet-form-builder/validation-messages', | |
| 62 | - array( | |
| 63 | - new Messages\Is_Empty_Value(), | |
| 64 | - new Messages\Is_Number_Min(), | |
| 65 | - new Messages\Is_Number_Max(), | |
| 66 | - new Messages\Is_Char_Min(), | |
| 67 | - new Messages\Is_Char_Max(), | |
| 68 | - new Messages\Is_Not_Valid_Email(), | |
| 69 | - new Messages\Is_Not_Valid_Url(), | |
| 70 | - new Messages\Is_Not_Complete_Mask(), | |
| 71 | - new Messages\Is_Files_Max(), | |
| 72 | - new Messages\Is_File_Size(), | |
| 73 | - new Messages\Is_File_Ext(), | |
| 74 | - new Messages\Is_Date_Min(), | |
| 75 | - new Messages\Is_Date_Max(), | |
| 76 | - ) | |
| 77 | - ); | |
| 78 | - | |
| 79 | 58 | /** @var \JFB_Modules\Post_Type\Module $post_type */ |
| 80 | 59 | $post_type = jet_form_builder()->module( 'post-type' ); |
| 81 | 60 | $post_type->get_meta()->install( new Post_Type\Validation_Meta() ); |
| 82 | 61 | |
| @@ -88,9 +67,10 @@ | ||
| 88 | 67 | /** |
| 89 | 68 | * @throws Repository_Exception |
| 90 | 69 | */ |
| 91 | 70 | public function on_uninstall() { |
| 92 | - unset( $this->rules, $this->messages ); | |
| 71 | + $this->rules = null; | |
| 72 | + $this->messages = array(); | |
| 93 | 73 | |
| 94 | 74 | /** @var \JFB_Modules\Post_Type\Module $post_type */ |
| 95 | 75 | $post_type = jet_form_builder()->module( 'post-type' ); |
| 96 | 76 | $post_type->get_meta()->uninstall( Post_Type\Validation_Meta::class ); |
| @@ -267,9 +247,11 @@ | ||
| 267 | 247 | 'type' => $validation['type'] ?? self::FORMAT_BROWSER, |
| 268 | 248 | 'messages' => array(), |
| 269 | 249 | ); |
| 270 | 250 | |
| 271 | - foreach ( $this->messages as $message ) { | |
| 251 | + $messages = $this->get_messages(); | |
| 252 | + | |
| 253 | + foreach ( $messages as $message ) { | |
| 272 | 254 | $response['messages'][ $message->get_id() ] = ( |
| 273 | 255 | $validation['messages'][ $message->get_id() ] ?? $message->get_initial() |
| 274 | 256 | ); |
| 275 | 257 | } |
| @@ -308,9 +290,13 @@ | ||
| 308 | 290 | ); |
| 309 | 291 | } |
| 310 | 292 | |
| 311 | 293 | public function validate_block( Field_Data_Parser $parser ) { |
| 312 | - if ( ! $this->is_advanced( $parser->get_settings() ) ) { | |
| 294 | + if ( | |
| 295 | + ! $this->is_advanced( $parser->get_settings() ) || | |
| 296 | + ! $parser->get_value() || | |
| 297 | + $parser->is_inside_conditional() | |
| 298 | + ) { | |
| 313 | 299 | return; |
| 314 | 300 | } |
| 315 | 301 | |
| 316 | 302 | $this->get_rules()->validate_block( $parser ); |
| @@ -320,12 +306,12 @@ | ||
| 320 | 306 | wp_localize_script( |
| 321 | 307 | Editor::EDITOR_PACKAGE_HANDLE, |
| 322 | 308 | 'jetFormValidation', |
| 323 | 309 | array( |
| 324 | - 'messages' => Array_Tools::to_array( $this->messages ), | |
| 325 | - 'ssr_callbacks' => Array_Tools::to_array( $this->rules->get_ssr()->get_callbacks() ), | |
| 310 | + 'messages' => Array_Tools::to_array( $this->get_messages() ), | |
| 311 | + 'ssr_callbacks' => Array_Tools::to_array( $this->get_rules()->get_ssr()->get_callbacks() ), | |
| 326 | 312 | 'formats' => $this->formats(), |
| 327 | - 'rule_types' => Array_Tools::to_array( $this->rules->rep_get_values() ), | |
| 313 | + 'rule_types' => Array_Tools::to_array( $this->get_rules()->rep_get_values() ), | |
| 328 | 314 | ) |
| 329 | 315 | ); |
| 330 | 316 | } |
| 331 | 317 | |
| @@ -332,8 +318,41 @@ | ||
| 332 | 318 | /** |
| 333 | 319 | * @return Rules_Controller |
| 334 | 320 | */ |
| 335 | 321 | public function get_rules(): Rules_Controller { |
| 322 | + if ( ! is_null( $this->rules ) ) { | |
| 323 | + return $this->rules; | |
| 324 | + } | |
| 325 | + | |
| 326 | + $this->rules = new Rules_Controller(); | |
| 327 | + | |
| 336 | 328 | return $this->rules; |
| 329 | + } | |
| 330 | + | |
| 331 | + public function get_messages(): array { | |
| 332 | + if ( ! empty( $this->messages ) ) { | |
| 333 | + return $this->messages; | |
| 334 | + } | |
| 335 | + | |
| 336 | + $this->messages = apply_filters( | |
| 337 | + 'jet-form-builder/validation-messages', | |
| 338 | + array( | |
| 339 | + new Messages\Is_Empty_Value(), | |
| 340 | + new Messages\Is_Number_Min(), | |
| 341 | + new Messages\Is_Number_Max(), | |
| 342 | + new Messages\Is_Char_Min(), | |
| 343 | + new Messages\Is_Char_Max(), | |
| 344 | + new Messages\Is_Not_Valid_Email(), | |
| 345 | + new Messages\Is_Not_Valid_Url(), | |
| 346 | + new Messages\Is_Not_Complete_Mask(), | |
| 347 | + new Messages\Is_Files_Max(), | |
| 348 | + new Messages\Is_File_Size(), | |
| 349 | + new Messages\Is_File_Ext(), | |
| 350 | + new Messages\Is_Date_Min(), | |
| 351 | + new Messages\Is_Date_Max(), | |
| 352 | + ) | |
| 353 | + ); | |
| 354 | + | |
| 355 | + return $this->messages; | |
| 337 | 356 | } |
| 338 | 357 | |
| 339 | 358 | } |