PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / forms / includes / control-holder.class.php
robin-image-optimizer / libs / factory / forms / includes Last commit date
providers 5 months ago complex-control.class.php 5 months ago control-holder.class.php 5 months ago control.class.php 5 months ago custom-element.class.php 5 months ago form-element.class.php 5 months ago form-layout.class.php 5 months ago form.class.php 5 months ago holder.class.php 5 months ago html-builder.class.php 5 months ago index.php 5 months ago
control-holder.class.php
162 lines
1 <?php
2 /**
3 * The file contains the base class for all control holder
4 *
5 * @package factory-forms
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 if ( ! class_exists( 'Wbcr_FactoryForms600_ControlHolder' ) ) {
15 /**
16 * The base class for control holders.
17 *
18 * @since 1.0.0
19 */
20 abstract class Wbcr_FactoryForms600_ControlHolder extends Wbcr_FactoryForms600_Control {
21
22 /**
23 * Holder Elements.
24 *
25 * @since 1.0.0
26 * @var Wbcr_FactoryForms600_Control[]
27 */
28 protected $elements = [];
29
30 /**
31 * Is this element a control holder?
32 *
33 * @since 1.0.0
34 * @var bool
35 */
36 public $is_holder = true;
37
38 /**
39 * Creates a new instance of control holder.
40 *
41 * @since 1.0.0
42 * @param mixed[] $options A holder options.
43 * @param Wbcr_FactoryForms600_Form $form A parent form.
44 */
45 public function __construct( $options, $form ) {
46 parent::__construct( $options, $form );
47
48 $this->elements = $form->createElements( $options['items'] );
49
50 foreach ( (array) $this->elements as $val ) {
51 $val->parent = $this;
52 }
53 }
54
55 /**
56 * Returns holder elements.
57 *
58 * @since 1.0.0
59 * @return Wbcr_FactoryForms600_FormElement[].
60 */
61 public function getElements() {
62 return $this->elements;
63 }
64
65 /**
66 * Renders the form or a given control holder.
67 *
68 * @since 1.0.0
69 * @return void
70 */
71 function render() {
72 $this->beforeRendering();
73
74 $is_first_item = true;
75
76 foreach ( $this->elements as $element ) {
77 $element->setOption( 'isFirst', $is_first_item );
78
79 if ( $is_first_item ) {
80 $is_first_item = false;
81 }
82
83 do_action( 'wbcr_factory_form_before_element_' . $element->getName() );
84
85 // if a current item is a control holder
86 if ( $element->is_holder ) {
87
88 $this->form->layout->beforeHolder( $element );
89 $element->render();
90 $this->form->layout->afterHolder( $element );
91 // if a current item is an input control
92 } elseif ( $element->is_control ) {
93
94 $this->form->layout->beforeControl( $element );
95 $element->render();
96 $this->form->layout->afterControl( $element );
97 // if a current item is a custom form element
98 } elseif ( $element->is_custom ) {
99
100 $element->render();
101 // otherwise, show the error
102 } else {
103 echo( '[ERROR] Invalid item.' );
104 }
105
106 do_action( 'wbcr_factory_form_after_element_' . $element->getName() );
107 }
108
109 $this->afterRendering();
110 }
111
112 /**
113 * Rendering a beginning of a holder.
114 *
115 * @since 1.0.0
116 * @return void
117 */
118 public function beforeRendering() {
119 }
120
121 /**
122 * Rendering an end of a holder.
123 *
124 * @since 1.0.0
125 * @return void
126 */
127 public function afterRendering() {
128 }
129
130 /**
131 * Rendering some html before an inner holder.
132 *
133 * @since 1.0.0
134 * @return void
135 */
136 public function beforeInnerHolder() {
137 }
138
139 /**
140 * Rendering some html after an inner holder.
141 *
142 * @since 1.0.0
143 * @return void
144 */
145 public function afterInnerHolder() {
146 }
147
148
149 public function beforeInnerElement() {
150 }
151
152 /**
153 * Rendering some html after an inner element.
154 *
155 * @since 1.0.0
156 * @return void
157 */
158 public function afterInnerElement() {
159 }
160 }
161 }
162