PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 +27 -87 6.355.4 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,35 +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 ) {
141 + if ( false === $this->parent_li || ! empty( $this->section_helper ) ) {
160 142 return false;
161 143 }
162 -
163 - /**
164 - * Fields that sit inside an open section are wrapped by that section's own helper, so the
165 - * row here is not theirs to close. set_field() opens the section helper for the section
166 - * field itself, one step ahead of this check, and section_is_open is not set until
167 - * sync_list_size() runs afterwards. Testing both is what keeps the section field subject to
168 - * the width check below rather than being treated as though it were already inside itself.
169 - *
170 - * @see https://github.com/Strategy11/formidable-pro/issues/3820
171 - */
172 - if ( $this->section_helper && $this->section_is_open ) {
173 - return false;
174 - }
175 -
176 144 if ( 'end_divider' === $this->field->type ) {
177 145 return false;
178 146 }
179 -
180 147 return ! $this->can_support_current_layout() || $this->is_frm_first;
181 148 }
182 149
183 - /**
184 - * @return void
185 - */
186 150 private function begin_field_wrapper() {
187 151 echo '<li class="frm_field_box"><ul class="frm_grid_container frm_sorting">';
188 152 $this->parent_li = true;
189 153 $this->current_list_size = 0;
@@ -191,9 +155,8 @@
191 155 }
192 156
193 157 /**
194 158 * @param string $class
195 - *
196 159 * @return int
197 160 */
198 161 private static function get_size_of_class( $class ) {
199 162 switch ( $class ) {
@@ -210,11 +173,10 @@
210 173 case 'frm_sixth':
211 174 return 2;
212 175 }
213 176
214 - if ( str_starts_with( $class, 'frm' ) ) {
177 + if ( 0 === strpos( $class, 'frm' ) ) {
215 178 $substr = substr( $class, 3 );
216 -
217 179 if ( is_numeric( $substr ) ) {
218 180 return (int) $substr;
219 181 }
220 182 }
@@ -222,13 +184,10 @@
222 184 // Anything missing a layout class should be a full width row.
223 185 return 12;
224 186 }
225 187
226 - /**
227 - * @return void
228 - */
229 188 public function sync_list_size() {
230 - if ( ! $this->field ) {
189 + if ( ! isset( $this->field ) ) {
231 190 return;
232 191 }
233 192
234 193 if ( 'divider' === $this->field->type ) {
@@ -234,35 +193,28 @@
234 193 if ( 'divider' === $this->field->type ) {
235 194 $this->section_is_open = true;
236 195 }
237 196
238 - if ( $this->section_helper ) {
197 + if ( ! empty( $this->section_helper ) ) {
239 198 $this->section_helper->sync_list_size();
240 -
241 199 if ( 'end_divider' === $this->field->type ) {
242 200 $this->maybe_close_section_helper();
243 201 }
244 -
245 202 return;
246 203 }
247 204
248 - if ( false === $this->parent_li ) {
249 - 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 + }
250 211 }
251 -
252 - ++$this->current_field_count;
253 - $this->current_list_size += $this->active_field_size;
254 -
255 - if ( 12 === $this->current_list_size ) {
256 - $this->close_field_wrapper();
257 - }
258 212 }
259 213
260 214 /**
261 215 * It is possible that there was still space for another field so the wrapper could still be open after looping the fields.
262 216 * If it is, make sure it's closed now.
263 - *
264 - * @return void
265 217 */
266 218 public function force_close_field_wrapper() {
267 219 if ( false !== $this->parent_li ) {
268 220 $this->close_field_wrapper();
@@ -268,18 +220,10 @@
268 220 $this->close_field_wrapper();
269 221 }
270 222 }
271 223
272 - /**
273 - * @return void
274 - */
275 224 private function close_field_wrapper() {
276 - // Only an open section has a nested wrapper to close. A section helper that set_field() has
277 - // just created belongs to the section about to start, so closing this row must leave it alone.
278 - if ( $this->section_is_open ) {
279 - $this->maybe_close_section_helper();
280 - }
281 -
225 + $this->maybe_close_section_helper();
282 226 echo '</ul></li>';
283 227 $this->parent_li = false;
284 228 $this->current_list_size = 0;
285 229 $this->current_field_count = 0;
@@ -284,11 +228,8 @@
284 228 $this->current_list_size = 0;
285 229 $this->current_field_count = 0;
286 230 }
287 231
288 - /**
289 - * @return bool
290 - */
291 232 private function can_support_current_layout() {
292 233 if ( 'end_divider' === $this->field->type ) {
293 234 return true;
294 235 }
@@ -296,13 +237,12 @@
296 237 }
297 238
298 239 /**
299 240 * @param string $class
300 - *
301 241 * @return bool
302 242 */
303 243 private function can_support_an_additional_layout( $class ) {
304 - $size = self::get_size_of_class( $class );
244 + $size = $this->get_size_of_class( $class );
305 245 return $this->current_list_size + $size <= 12;
306 246 }
307 247
308 248 /**