PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.0.2
JetFormBuilder — Dynamic Blocks Form Builder v2.0.2
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 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / request / field-data-parser.php
jetformbuilder / includes / request Last commit date
exceptions 4 years ago fields 4 years ago field-data-parser.php 4 years ago form-request-router.php 4 years ago parser-manager.php 4 years ago request-handler.php 4 years ago request-router.php 4 years ago
field-data-parser.php
110 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Request;
5
6 use Jet_Form_Builder\Blocks\Modules\Fields_Errors\Error_Handler;
7 use Jet_Form_Builder\Classes\Repository\Repository_Item_Instance_Trait;
8 use Jet_Form_Builder\Request\Exceptions\Exclude_Field_Exception;
9
10 abstract class Field_Data_Parser implements Repository_Item_Instance_Trait {
11
12 protected $value;
13 protected $is_required = false;
14 protected $name = 'field_name';
15 protected $block;
16 protected $settings;
17 protected $inner;
18 protected $request_handler;
19 protected $inside_conditional;
20
21 abstract public function type();
22
23 /**
24 * @return string
25 */
26 public function rep_item_id() {
27 return $this->type();
28 }
29
30 public function get_response() {
31 return $this->value;
32 }
33
34 /**
35 * @param $value
36 * @param $block
37 * @param $inside_conditional
38 *
39 * @return mixed
40 * @throws Exclude_Field_Exception
41 */
42 final public function get_parsed_value( $value, $block, $inside_conditional ) {
43 $this->init( $value, $block, $inside_conditional )->is_field_visible();
44
45 return $this->response();
46 }
47
48 final public function response() {
49 if ( $this->has_error() ) {
50 $this->save_error();
51 }
52
53 return $this->get_response();
54 }
55
56 public function parse_value( $value ) {
57 return $value;
58 }
59
60 public function init( $value, $block, $inside_conditional ): Field_Data_Parser {
61 $this->block = $block;
62 $this->inside_conditional = $inside_conditional;
63 $this->settings = $this->block['attrs'];
64 $this->inner = $this->block['innerBlocks'];
65
66 if ( isset( $this->settings['required'] ) ) {
67 $this->is_required = $this->settings['required'];
68 }
69 if ( isset( $this->settings['name'] ) ) {
70 $this->name = $this->settings['name'];
71 }
72 $this->value = $this->parse_value( $value );
73
74 return $this;
75 }
76
77 protected function has_error(): bool {
78 return ( ! $this->inside_conditional && $this->is_required && empty( $this->value ) );
79 }
80
81 protected function save_error() {
82 Error_Handler::instance()->add(
83 $this->type(),
84 array(
85 'name' => $this->name,
86 'params' => $this->settings,
87 )
88 );
89 }
90
91 /**
92 * @throws Exclude_Field_Exception
93 */
94 protected function is_field_visible() {
95 $visibility = $this->settings['visibility'] ?? true;
96
97 // If is visible for logged in users and user is logged in - show field.
98 if ( 'logged_id' === $visibility && ! is_user_logged_in() ) {
99 throw new Exclude_Field_Exception();
100 }
101
102 // If is visible for not logged in users and user is not logged in - show field.
103 if ( 'not_logged_in' === $visibility && is_user_logged_in() ) {
104 throw new Exclude_Field_Exception();
105 }
106 }
107
108
109 }
110