PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 1.1.1
JetFormBuilder — Dynamic Blocks Form Builder v1.1.1
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / request / field-data-parser.php
field-data-parser.php
63 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Request;
5
6
7 use Jet_Form_Builder\Blocks\Modules\Fields_Errors\Error_Handler;
8
9 abstract class Field_Data_Parser {
10
11 protected $value;
12 protected $is_required = false;
13 protected $name = 'field_name';
14 protected $block;
15 protected $settings;
16 protected $inner;
17
18 abstract public function type();
19
20 public function get_response() {
21 return $this->value;
22 }
23
24 public function _is_custom_check() {
25 return false;
26 }
27
28 final public function response() {
29 if ( $this->_is_required() || $this->_is_custom_check() ) {
30 $this->save_error();
31 }
32
33 return $this->get_response();
34 }
35
36 public function init( $value, $block ) {
37 $this->value = $value;
38 $this->block = $block;
39
40 $this->settings = $this->block['attrs'];
41 $this->inner = $this->block['innerBlocks'];
42
43 if ( isset( $this->settings['required'] ) ) {
44 $this->is_required = $this->settings['required'];
45 }
46 if ( isset( $this->settings['name'] ) ) {
47 $this->name = $this->settings['name'];
48 }
49 }
50
51
52 private function _is_required() {
53 return ( $this->is_required && empty( $this->value ) );
54 }
55
56 private function save_error() {
57 Error_Handler::instance()->add(
58 $this->type(), array( 'name' => $this->name, 'params' => $this->settings )
59 );
60 }
61
62
63 }