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