PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.1
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 +19 -62 6.286.1 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,10 +62,8 @@
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
@@ -89,23 +78,18 @@
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 || ! empty( $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 93 if ( empty( $this->section_helper ) ) {
110 94 return;
111 95 }
@@ -135,11 +119,8 @@
135 119
136 120 return '';
137 121 }
138 122
139 - /**
140 - * @return void
141 - */
142 123 public function maybe_begin_field_wrapper() {
143 124 if ( $this->should_first_close_the_active_field_wrapper() ) {
144 125 $this->close_field_wrapper();
145 126 }
@@ -159,19 +140,14 @@
159 140 private function should_first_close_the_active_field_wrapper() {
160 141 if ( false === $this->parent_li || ! empty( $this->section_helper ) ) {
161 142 return false;
162 143 }
163 -
164 144 if ( 'end_divider' === $this->field->type ) {
165 145 return false;
166 146 }
167 -
168 147 return ! $this->can_support_current_layout() || $this->is_frm_first;
169 148 }
170 149
171 - /**
172 - * @return void
173 - */
174 150 private function begin_field_wrapper() {
175 151 echo '<li class="frm_field_box"><ul class="frm_grid_container frm_sorting">';
176 152 $this->parent_li = true;
177 153 $this->current_list_size = 0;
@@ -179,9 +155,8 @@
179 155 }
180 156
181 157 /**
182 158 * @param string $class
183 - *
184 159 * @return int
185 160 */
186 161 private static function get_size_of_class( $class ) {
187 162 switch ( $class ) {
@@ -198,11 +173,10 @@
198 173 case 'frm_sixth':
199 174 return 2;
200 175 }
201 176
202 - if ( str_starts_with( $class, 'frm' ) ) {
177 + if ( 0 === strpos( $class, 'frm' ) ) {
203 178 $substr = substr( $class, 3 );
204 -
205 179 if ( is_numeric( $substr ) ) {
206 180 return (int) $substr;
207 181 }
208 182 }
@@ -210,13 +184,10 @@
210 184 // Anything missing a layout class should be a full width row.
211 185 return 12;
212 186 }
213 187
214 - /**
215 - * @return void
216 - */
217 188 public function sync_list_size() {
218 - if ( empty( $this->field ) ) {
189 + if ( ! isset( $this->field ) ) {
219 190 return;
220 191 }
221 192
222 193 if ( 'divider' === $this->field->type ) {
@@ -224,33 +195,26 @@
224 195 }
225 196
226 197 if ( ! empty( $this->section_helper ) ) {
227 198 $this->section_helper->sync_list_size();
228 -
229 199 if ( 'end_divider' === $this->field->type ) {
230 200 $this->maybe_close_section_helper();
231 201 }
232 -
233 202 return;
234 203 }
235 204
236 - if ( false === $this->parent_li ) {
237 - 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 + }
238 211 }
239 -
240 - ++$this->current_field_count;
241 - $this->current_list_size += $this->active_field_size;
242 -
243 - if ( 12 === $this->current_list_size ) {
244 - $this->close_field_wrapper();
245 - }
246 212 }
247 213
248 214 /**
249 215 * It is possible that there was still space for another field so the wrapper could still be open after looping the fields.
250 216 * If it is, make sure it's closed now.
251 - *
252 - * @return void
253 217 */
254 218 public function force_close_field_wrapper() {
255 219 if ( false !== $this->parent_li ) {
256 220 $this->close_field_wrapper();
@@ -256,11 +220,8 @@
256 220 $this->close_field_wrapper();
257 221 }
258 222 }
259 223
260 - /**
261 - * @return void
262 - */
263 224 private function close_field_wrapper() {
264 225 $this->maybe_close_section_helper();
265 226 echo '</ul></li>';
266 227 $this->parent_li = false;
@@ -267,11 +228,8 @@
267 228 $this->current_list_size = 0;
268 229 $this->current_field_count = 0;
269 230 }
270 231
271 - /**
272 - * @return bool
273 - */
274 232 private function can_support_current_layout() {
275 233 if ( 'end_divider' === $this->field->type ) {
276 234 return true;
277 235 }
@@ -279,13 +237,12 @@
279 237 }
280 238
281 239 /**
282 240 * @param string $class
283 - *
284 241 * @return bool
285 242 */
286 243 private function can_support_an_additional_layout( $class ) {
287 - $size = self::get_size_of_class( $class );
244 + $size = $this->get_size_of_class( $class );
288 245 return $this->current_list_size + $size <= 12;
289 246 }
290 247
291 248 /**