PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.5.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 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 / actions / methods / base-object-property.php
jetformbuilder / includes / actions / methods Last commit date
exceptions 2 years ago abstract-modifier.php 1 year ago base-modifier-action.php 2 years ago base-object-property.php 2 years ago object-dynamic-property.php 2 years ago object-properties-collection.php 2 years ago
base-object-property.php
138 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Actions\Methods;
5
6 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
7 use Jet_Form_Builder\Classes\Arrayable\Collection;
8 use Jet_Form_Builder\Classes\Arrayable\Collection_Item_Interface;
9 use Jet_Form_Builder\Exceptions\Silence_Exception;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 abstract class Base_Object_Property implements
17 Collection_Item_Interface,
18 Arrayable {
19
20 protected $value = null;
21 protected $is_excluded = false;
22
23 abstract public function get_label(): string;
24
25 public function set_value( string $key, $value, Abstract_Modifier $modifier ) {
26 if ( ! $this->can_attach( $key, $value ) ) {
27 return;
28 }
29 /**
30 * This is necessary for those cases when we need to set
31 * (or not) some property and then build on it.
32 */
33 $this->set_related( $modifier );
34 $this->do_before( $key, $value, $modifier );
35 }
36
37 /**
38 * For dynamic properties, it cannot be constant,
39 * so we pass it through parameters
40 *
41 * @param string $key
42 *
43 * @param $value
44 * @param Abstract_Modifier $modifier
45 */
46 public function do_before( string $key, $value, Abstract_Modifier $modifier ) {
47 $this->value = $value;
48 }
49
50 public function do_after( Abstract_Modifier $modifier ) {
51 }
52
53 public function can_attach( string $key, $value ): bool {
54 if ( is_a( $this, Object_Dynamic_Property::class ) ) {
55 return $this->is_supported( $key, $value );
56 }
57
58 return ! $this->is_excluded && is_null( $this->value );
59 }
60
61 /**
62 * @return null
63 * @throws Silence_Exception
64 */
65 public function get_value( Abstract_Modifier $modifier ) {
66 if ( ! is_null( $this->value ) ) {
67 return $this->value;
68 }
69 throw new Silence_Exception( 'Empty value' );
70 }
71
72 public function exclude() {
73 $this->is_excluded = true;
74 }
75
76 protected function set_related( Abstract_Modifier $modifier ) {
77 $related = $modifier->properties->get_by_ids( $this->get_related() );
78
79 /** @var Base_Object_Property $property */
80 foreach ( $related as $property ) {
81 $field_name = $modifier->get_field_name_by_prop( $property->get_id() );
82
83 if ( false === $field_name ) {
84 continue;
85 }
86
87 if ( $property->get_id() === $this->get_id() ) {
88 wp_die(
89 esc_attr(
90 sprintf(
91 /* translators: %s - object property name */
92 __(
93 'Logic error. Property [%s] can not be related by itself.',
94 'jet-form-builder'
95 ),
96 $property->get_id()
97 )
98 )
99 );
100 }
101 $value = $modifier->get_value( $field_name );
102
103 $property->set_value( $property->get_id(), $value, $modifier );
104 }
105 }
106
107 /**
108 * @return string
109 */
110 public function get_attach_id(): string {
111 return $this->get_id();
112 }
113
114 public function get_help(): string {
115 return '';
116 }
117
118 /**
119 * @return string[]
120 */
121 public function get_related(): array {
122 return array();
123 }
124
125 public function is_merge_value(): bool {
126 return false;
127 }
128
129 public function to_array(): array {
130 return array(
131 'value' => $this->get_id(),
132 'label' => $this->get_label(),
133 'help' => $this->get_help(),
134 );
135 }
136
137 }
138