PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.6
JetFormBuilder — Dynamic Blocks Form Builder v2.1.6
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 / admin / single-pages / meta-containers / base-meta-container.php
jetformbuilder / includes / admin / single-pages / meta-containers Last commit date
base-meta-container.php 3 years ago normal-meta-container.php 3 years ago side-meta-container.php 3 years ago
base-meta-container.php
130 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Single_Pages\Meta_Containers;
5
6 use Jet_Form_Builder\Admin\Exceptions\Empty_Box_Exception;
7 use Jet_Form_Builder\Admin\Single_Pages\Meta_Boxes\Base_Meta_Box;
8 use Jet_Form_Builder\Classes\Arrayable\Arrayable;
9 use Jet_Form_Builder\Classes\Repository\Repository_Pattern_Trait;
10 use Jet_Form_Builder\Exceptions\Repository_Exception;
11
12 abstract class Base_Meta_Container implements Arrayable {
13
14 use Repository_Pattern_Trait;
15
16 const TYPE_NORMAL = 'normal-sortables';
17 const TYPE_SIDE = 'side-sortables';
18
19 protected $index;
20
21 public function get_type(): string {
22 return 1 !== $this->index ? self::TYPE_NORMAL : self::TYPE_SIDE;
23 }
24
25 /**
26 * @return string[]
27 */
28 public function get_classes(): array {
29 return array(
30 'meta-box-sortables',
31 'ui-sortable',
32 );
33 }
34
35 /**
36 * Base_Meta_Container constructor.
37 *
38 * @param Base_Meta_Box[] $meta_boxes
39 */
40 public function __construct( ...$meta_boxes ) {
41 $this->rep_install( $meta_boxes );
42 }
43
44 public function rep_instances(): array {
45 return array();
46 }
47
48 /**
49 * @return Base_Meta_Box[]
50 */
51 public function get_boxes(): array {
52 return $this->rep_get_values();
53 }
54
55 public function get_box( string $slug ): Base_Meta_Box {
56 return $this->rep_get_item_or_die( $slug );
57 }
58
59 /**
60 * @param string $scoped_slug
61 *
62 * @return Base_Meta_Box
63 * @throws Repository_Exception
64 */
65 public function get_box_by_scope( string $scoped_slug ): Base_Meta_Box {
66 // cut the `scope-`
67 $slug = substr( $scoped_slug, 6, 0 );
68
69 foreach ( $this->get_boxes() as $box ) {
70 if ( $box->get_slug() === $slug ) {
71 return $box;
72 }
73 }
74
75 throw new Repository_Exception( 'Undefined ' . $scoped_slug );
76 }
77
78 public function get_migrations(): \Generator {
79 foreach ( $this->get_boxes() as $box ) {
80 yield from $box->get_migrations();
81 }
82 }
83
84 /**
85 * @param Base_Meta_Box $box
86 */
87 public function add_meta_box( Base_Meta_Box $box ) {
88 $this->rep_install_item_soft( $box );
89 }
90
91 /**
92 * @param Base_Meta_Box $item
93 *
94 * @throws Repository_Exception
95 */
96 public function rep_before_install_item( $item ) {
97 if ( ! $item->is_active() ) {
98 $this->_rep_abort_this();
99 }
100 }
101
102 public function set_index( int $index ): Base_Meta_Container {
103 $this->index = $index;
104
105 return $this;
106 }
107
108 public function to_array(): array {
109 $boxes = array();
110 $storage = jet_fb_current_page()->get_storage();
111
112 foreach ( $this->get_boxes() as $box ) {
113 try {
114 $box->set_single_id();
115
116 $boxes[] = $storage->to_array( $box );
117 } catch ( Empty_Box_Exception $exception ) {
118 continue;
119 }
120 }
121
122 return array(
123 'wrap_id' => "postbox-container-{$this->index}",
124 'id' => $this->get_type(),
125 'classes' => implode( ' ', $this->get_classes() ),
126 'boxes' => $boxes,
127 );
128 }
129 }
130