PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 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 All 134 releases
jetformbuilder / includes / blocks / conditional-block / render-states-collection.php

render-states-collection.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at includes/blocks/conditional-block/render-states-collection.php

72 lines 1.4 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\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\Custom_Render_State;
8 use Jet_Form_Builder\Classes\Arrayable\Collection;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 class Render_States_Collection extends Collection {
16
17 private $exclude_list = array();
18
19 /**
20 * @param Base_Render_State|string $item
21 *
22 * @return Collection
23 */
24 public function push( $item ): Collection {
25 if ( ! is_object( $item ) ) {
26 $custom = new Custom_Render_State();
27 $custom->set_id( $item );
28
29 return $this->push( $custom );
30 }
31
32 $states = $item->exclude_states();
33
34 if ( count( $states ) ) {
35 array_push( $this->exclude_list, ...$states );
36 }
37
38 return $this->add( $item );
39 }
40
41 public function confirm(): Collection {
42 $positions = array();
43
44 foreach ( $this as $position => $state ) {
45 $current = get_class( $state );
46
47 if ( ! in_array( $current, $this->exclude_list, true ) ) {
48 continue;
49 }
50
51 $positions[] = $position;
52 }
53
54 $this->remove( $positions );
55 $this->exclude_list = array();
56
57 return $this;
58 }
59
60 public function render(): string {
61 $response = '';
62
63 /** @var Base_Render_State $item */
64 foreach ( $this as $item ) {
65 $response .= "\r\n" . $item->render();
66 }
67
68 return $response;
69 }
70
71 }
72