PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmFieldGridHelper.php +26 -68 6.325.0 View file →
@@ -4,11 +4,8 @@
4 4 }
5 5
6 6 class FrmFieldGridHelper {
7 7
8 - /**
9 - * @var bool
10 - */
11 8 private $parent_li;
12 9
13 10 /**
14 11 * @var int
@@ -30,40 +27,34 @@
30 27 */
31 28 private $active_field_size;
32 29
33 30 /**
34 - * @var bool flagged while calling get_field_layout_class, true if classes contain frm_first class.
31 + * @var bool $is_frm_first flagged while calling get_field_layout_class, true if classes contain frm_first class.
35 32 */
36 33 private $is_frm_first;
37 34
38 35 /**
39 - * @var stdClass|null
36 + * @var stdClass
40 37 */
41 38 private $field;
42 39
43 40 /**
44 - * @var FrmFieldGridHelper|null
41 + * @var FrmFieldGridHelper $section_helper
45 42 */
46 43 private $section_helper;
47 44
48 45 /**
49 - * @var bool
46 + * @var bool $nested
50 47 */
51 48 private $nested;
52 49
53 50 /**
54 - * @var int
51 + * @var int $section_size
55 52 */
56 53 private $section_size;
57 54
58 - /**
59 - * @var bool
60 - */
61 55 private $section_is_open = false;
62 56
63 - /**
64 - * @param bool $nested
65 - */
66 57 public function __construct( $nested = false ) {
67 58 $this->parent_li = false;
68 59 $this->current_list_size = 0;
69 60 $this->current_field_count = 0;
@@ -71,15 +62,13 @@
71 62 }
72 63
73 64 /**
74 65 * @param stdClass $field
75 - *
76 - * @return void
77 66 */
78 67 public function set_field( $field ) {
79 68 $this->field = $field;
80 69
81 - if ( $this->section_helper && 'end_divider' !== $field->type ) {
70 + if ( ! empty( $this->section_helper ) && 'end_divider' !== $field->type ) {
82 71 $this->section_helper->set_field( $field );
83 72 return;
84 73 }
85 74
@@ -89,25 +78,20 @@
89 78 $this->section_is_open = false;
90 79 $this->maybe_close_section_helper();
91 80 } else {
92 81 $this->field_layout_class = $this->get_field_layout_class();
93 - $this->active_field_size = self::get_size_of_class( $this->field_layout_class );
82 + $this->active_field_size = $this->get_size_of_class( $this->field_layout_class );
94 83 }
95 84
96 - if ( 'divider' !== $field->type || $this->nested ) {
97 - return;
85 + if ( 'divider' === $field->type && empty( $this->nested ) ) {
86 + $this->section_size = $this->active_field_size;
87 + $this->active_field_size = 0;
88 + $this->section_helper = new self( true );
98 89 }
99 -
100 - $this->section_size = $this->active_field_size;
101 - $this->active_field_size = 0;
102 - $this->section_helper = new self( true );
103 90 }
104 91
105 - /**
106 - * @return void
107 - */
108 92 private function maybe_close_section_helper() {
109 - if ( ! $this->section_helper ) {
93 + if ( empty( $this->section_helper ) ) {
110 94 return;
111 95 }
112 96 $this->section_helper->force_close_field_wrapper();
113 97 $this->section_helper = null;
@@ -124,10 +108,11 @@
124 108 }
125 109
126 110 $split = explode( ' ', $field['classes'] );
127 111 $this->is_frm_first = in_array( 'frm_first', $split, true );
112 + $classes = self::get_grid_classes();
128 113
129 - foreach ( self::get_grid_classes() as $class ) {
114 + foreach ( $classes as $class ) {
130 115 if ( in_array( $class, $split, true ) ) {
131 116 return $class;
132 117 }
133 118 }
@@ -134,11 +119,8 @@
134 119
135 120 return '';
136 121 }
137 122
138 - /**
139 - * @return void
140 - */
141 123 public function maybe_begin_field_wrapper() {
142 124 if ( $this->should_first_close_the_active_field_wrapper() ) {
143 125 $this->close_field_wrapper();
144 126 }
@@ -146,9 +128,9 @@
146 128 if ( false === $this->parent_li && 'end_divider' !== $this->field->type ) {
147 129 $this->begin_field_wrapper();
148 130 }
149 131
150 - if ( $this->section_helper && $this->section_is_open ) {
132 + if ( ! empty( $this->section_helper ) && $this->section_is_open ) {
151 133 $this->section_helper->maybe_begin_field_wrapper();
152 134 }
153 135 }
154 136
@@ -155,22 +137,17 @@
155 137 /**
156 138 * @return bool
157 139 */
158 140 private function should_first_close_the_active_field_wrapper() {
159 - if ( false === $this->parent_li || $this->section_helper ) {
141 + if ( false === $this->parent_li || ! empty( $this->section_helper ) ) {
160 142 return false;
161 143 }
162 -
163 144 if ( 'end_divider' === $this->field->type ) {
164 145 return false;
165 146 }
166 -
167 147 return ! $this->can_support_current_layout() || $this->is_frm_first;
168 148 }
169 149
170 - /**
171 - * @return void
172 - */
173 150 private function begin_field_wrapper() {
174 151 echo '<li class="frm_field_box"><ul class="frm_grid_container frm_sorting">';
175 152 $this->parent_li = true;
176 153 $this->current_list_size = 0;
@@ -178,9 +155,8 @@
178 155 }
179 156
180 157 /**
181 158 * @param string $class
182 - *
183 159 * @return int
184 160 */
185 161 private static function get_size_of_class( $class ) {
186 162 switch ( $class ) {
@@ -197,11 +173,10 @@
197 173 case 'frm_sixth':
198 174 return 2;
199 175 }
200 176
201 - if ( str_starts_with( $class, 'frm' ) ) {
177 + if ( 0 === strpos( $class, 'frm' ) ) {
202 178 $substr = substr( $class, 3 );
203 -
204 179 if ( is_numeric( $substr ) ) {
205 180 return (int) $substr;
206 181 }
207 182 }
@@ -209,13 +184,10 @@
209 184 // Anything missing a layout class should be a full width row.
210 185 return 12;
211 186 }
212 187
213 - /**
214 - * @return void
215 - */
216 188 public function sync_list_size() {
217 - if ( ! $this->field ) {
189 + if ( ! isset( $this->field ) ) {
218 190 return;
219 191 }
220 192
221 193 if ( 'divider' === $this->field->type ) {
@@ -221,35 +193,28 @@
221 193 if ( 'divider' === $this->field->type ) {
222 194 $this->section_is_open = true;
223 195 }
224 196
225 - if ( $this->section_helper ) {
197 + if ( ! empty( $this->section_helper ) ) {
226 198 $this->section_helper->sync_list_size();
227 -
228 199 if ( 'end_divider' === $this->field->type ) {
229 200 $this->maybe_close_section_helper();
230 201 }
231 -
232 202 return;
233 203 }
234 204
235 - if ( false === $this->parent_li ) {
236 - return;
205 + if ( false !== $this->parent_li ) {
206 + $this->current_field_count ++;
207 + $this->current_list_size += $this->active_field_size;
208 + if ( 12 === $this->current_list_size ) {
209 + $this->close_field_wrapper();
210 + }
237 211 }
238 -
239 - ++$this->current_field_count;
240 - $this->current_list_size += $this->active_field_size;
241 -
242 - if ( 12 === $this->current_list_size ) {
243 - $this->close_field_wrapper();
244 - }
245 212 }
246 213
247 214 /**
248 215 * It is possible that there was still space for another field so the wrapper could still be open after looping the fields.
249 216 * If it is, make sure it's closed now.
250 - *
251 - * @return void
252 217 */
253 218 public function force_close_field_wrapper() {
254 219 if ( false !== $this->parent_li ) {
255 220 $this->close_field_wrapper();
@@ -255,11 +220,8 @@
255 220 $this->close_field_wrapper();
256 221 }
257 222 }
258 223
259 - /**
260 - * @return void
261 - */
262 224 private function close_field_wrapper() {
263 225 $this->maybe_close_section_helper();
264 226 echo '</ul></li>';
265 227 $this->parent_li = false;
@@ -266,11 +228,8 @@
266 228 $this->current_list_size = 0;
267 229 $this->current_field_count = 0;
268 230 }
269 231
270 - /**
271 - * @return bool
272 - */
273 232 private function can_support_current_layout() {
274 233 if ( 'end_divider' === $this->field->type ) {
275 234 return true;
276 235 }
@@ -278,13 +237,12 @@
278 237 }
279 238
280 239 /**
281 240 * @param string $class
282 - *
283 241 * @return bool
284 242 */
285 243 private function can_support_an_additional_layout( $class ) {
286 - $size = self::get_size_of_class( $class );
244 + $size = $this->get_size_of_class( $class );
287 245 return $this->current_list_size + $size <= 12;
288 246 }
289 247
290 248 /**