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 / blocks / conditional-block / render-state.php
jetformbuilder / includes / blocks / conditional-block Last commit date
functions 3 years ago operators 3 years ago render-states 3 years ago condition-item.php 3 years ago condition-manager.php 3 years ago condition-response-object.php 3 years ago functions.php 3 years ago operators.php 3 years ago render-state.php 3 years ago render-states-collection.php 3 years ago
render-state.php
122 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Conditional_Block;
5
6 use Jet_Form_Builder\Blocks\Conditional_Block\Render_States\Base_Render_State;
7 use Jet_Form_Builder\Blocks\Conditional_Block\Render_States\Default_State;
8 use Jet_Form_Builder\Blocks\Conditional_Block\Render_States\Example_Render_State;
9 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
10 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
11 use Jet_Form_Builder\Classes\Instance_Trait;
12 use Jet_Form_Builder\Classes\Repository\Repository_Pattern_Trait;
13 use Jet_Form_Builder\Exceptions\Repository_Exception;
14
15 /**
16 * @method static Render_State instance()
17 *
18 * Class Render_State
19 * @package Jet_Form_Builder\Blocks\Conditional_Block
20 */
21 class Render_State implements Arrayable {
22
23 use Repository_Pattern_Trait;
24 use Instance_Trait;
25
26 /** @var Render_States_Collection */
27 private $current;
28
29 protected function __construct() {
30 $this->current = new Render_States_Collection();
31 $this->rep_install();
32 }
33
34 /**
35 * @return array
36 */
37 public function rep_instances(): array {
38 return apply_filters(
39 'jet-form-builder/render-states',
40 array(
41 new Default_State(),
42 new Example_Render_State(),
43 )
44 );
45 }
46
47 /**
48 * @param string $slug
49 *
50 * @return mixed
51 * @throws Repository_Exception
52 */
53 public function get_item( string $slug ) {
54 return $this->rep_get_item( $slug );
55 }
56
57 public function is_multiple(): bool {
58 $keys = $this->rep_get_keys();
59
60 return ( count( $keys ) > 1 );
61 }
62
63 /**
64 * @return $this
65 */
66 public function set_current(): Render_State {
67 if ( count( $this->current ) ) {
68 return $this;
69 }
70 $items = $this->rep_get_items();
71
72 /** @var Base_Render_State $render_state */
73 foreach ( $items as $render_state ) {
74 if ( ! $render_state->is_supported() ) {
75 continue;
76 }
77 $this->current->push( $render_state );
78 }
79
80 $this->set_current_default();
81
82 return $this;
83 }
84
85 public function set_current_default() {
86 if ( count( $this->current ) ) {
87 return;
88 }
89
90 try {
91 /** @var Default_State $state */
92 $state = $this->rep_get_item( Default_State::class );
93 } catch ( Repository_Exception $exception ) {
94 wp_die(
95 esc_html__( 'Something went wrong', 'jet-form-builder' ),
96 esc_html__( 'Error', 'jet-form-builder' )
97 );
98 }
99
100 $this->current->push( $state );
101 }
102
103 public function to_array(): array {
104 return Array_Tools::to_array( $this->rep_get_items() );
105 }
106
107 public function clear_current(): Render_State {
108 $this->current = new Render_States_Collection();
109
110 return $this;
111 }
112
113 /**
114 * @return Render_States_Collection
115 */
116 public function get_current(): Render_States_Collection {
117 return $this->current;
118 }
119
120
121 }
122