| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | |
| 6 | 6 | class FrmFieldGridHelper { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * @var bool|string | |
| 9 | + * @var bool | |
| 10 | 10 | */ |
| 11 | 11 | private $parent_li; |
| 12 | 12 | |
| 13 | 13 | /** |
| @@ -35,14 +35,14 @@ | ||
| 35 | 35 | */ |
| 36 | 36 | private $is_frm_first; |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | - * @var stdClass | |
| 39 | + * @var stdClass|null | |
| 40 | 40 | */ |
| 41 | 41 | private $field; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * @var FrmFieldGridHelper | |
| 44 | + * @var FrmFieldGridHelper|null | |
| 45 | 45 | */ |
| 46 | 46 | private $section_helper; |
| 47 | 47 | |
| 48 | 48 | /** |
| @@ -77,9 +77,9 @@ | ||
| 77 | 77 | */ |
| 78 | 78 | public function set_field( $field ) { |
| 79 | 79 | $this->field = $field; |
| 80 | 80 | |
| 81 | - if ( ! empty( $this->section_helper ) && 'end_divider' !== $field->type ) { | |
| 81 | + if ( $this->section_helper && 'end_divider' !== $field->type ) { | |
| 82 | 82 | $this->section_helper->set_field( $field ); |
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| @@ -92,13 +92,15 @@ | ||
| 92 | 92 | $this->field_layout_class = $this->get_field_layout_class(); |
| 93 | 93 | $this->active_field_size = self::get_size_of_class( $this->field_layout_class ); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( 'divider' === $field->type && empty( $this->nested ) ) { | |
| 97 | - $this->section_size = $this->active_field_size; | |
| 98 | - $this->active_field_size = 0; | |
| 99 | - $this->section_helper = new self( true ); | |
| 96 | + if ( 'divider' !== $field->type || $this->nested ) { | |
| 97 | + return; | |
| 100 | 98 | } |
| 99 | + | |
| 100 | + $this->section_size = $this->active_field_size; | |
| 101 | + $this->active_field_size = 0; | |
| 102 | + $this->section_helper = new self( true ); | |
| 101 | 103 | } |
| 102 | 104 | |
| 103 | 105 | /** |
| 104 | 106 | * @return void |
| @@ -103,9 +105,9 @@ | ||
| 103 | 105 | /** |
| 104 | 106 | * @return void |
| 105 | 107 | */ |
| 106 | 108 | private function maybe_close_section_helper() { |
| 107 | - if ( empty( $this->section_helper ) ) { | |
| 109 | + if ( ! $this->section_helper ) { | |
| 108 | 110 | return; |
| 109 | 111 | } |
| 110 | 112 | $this->section_helper->force_close_field_wrapper(); |
| 111 | 113 | $this->section_helper = null; |
| @@ -122,11 +124,10 @@ | ||
| 122 | 124 | } |
| 123 | 125 | |
| 124 | 126 | $split = explode( ' ', $field['classes'] ); |
| 125 | 127 | $this->is_frm_first = in_array( 'frm_first', $split, true ); |
| 126 | - $classes = self::get_grid_classes(); | |
| 127 | 128 | |
| 128 | - foreach ( $classes as $class ) { | |
| 129 | + foreach ( self::get_grid_classes() as $class ) { | |
| 129 | 130 | if ( in_array( $class, $split, true ) ) { |
| 130 | 131 | return $class; |
| 131 | 132 | } |
| 132 | 133 | } |
| @@ -145,9 +146,9 @@ | ||
| 145 | 146 | if ( false === $this->parent_li && 'end_divider' !== $this->field->type ) { |
| 146 | 147 | $this->begin_field_wrapper(); |
| 147 | 148 | } |
| 148 | 149 | |
| 149 | - if ( ! empty( $this->section_helper ) && $this->section_is_open ) { | |
| 150 | + if ( $this->section_helper && $this->section_is_open ) { | |
| 150 | 151 | $this->section_helper->maybe_begin_field_wrapper(); |
| 151 | 152 | } |
| 152 | 153 | } |
| 153 | 154 | |
| @@ -154,15 +155,29 @@ | ||
| 154 | 155 | /** |
| 155 | 156 | * @return bool |
| 156 | 157 | */ |
| 157 | 158 | private function should_first_close_the_active_field_wrapper() { |
| 158 | - if ( false === $this->parent_li || ! empty( $this->section_helper ) ) { | |
| 159 | + if ( false === $this->parent_li ) { | |
| 159 | 160 | return false; |
| 160 | 161 | } |
| 161 | 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 | + | |
| 162 | 176 | if ( 'end_divider' === $this->field->type ) { |
| 163 | 177 | return false; |
| 164 | 178 | } |
| 179 | + | |
| 165 | 180 | return ! $this->can_support_current_layout() || $this->is_frm_first; |
| 166 | 181 | } |
| 167 | 182 | |
| 168 | 183 | /** |
| @@ -195,9 +210,9 @@ | ||
| 195 | 210 | case 'frm_sixth': |
| 196 | 211 | return 2; |
| 197 | 212 | } |
| 198 | 213 | |
| 199 | - if ( 0 === strpos( $class, 'frm' ) ) { | |
| 214 | + if ( str_starts_with( $class, 'frm' ) ) { | |
| 200 | 215 | $substr = substr( $class, 3 ); |
| 201 | 216 | |
| 202 | 217 | if ( is_numeric( $substr ) ) { |
| 203 | 218 | return (int) $substr; |
| @@ -211,9 +226,9 @@ | ||
| 211 | 226 | /** |
| 212 | 227 | * @return void |
| 213 | 228 | */ |
| 214 | 229 | public function sync_list_size() { |
| 215 | - if ( empty( $this->field ) ) { | |
| 230 | + if ( ! $this->field ) { | |
| 216 | 231 | return; |
| 217 | 232 | } |
| 218 | 233 | |
| 219 | 234 | if ( 'divider' === $this->field->type ) { |
| @@ -219,24 +234,27 @@ | ||
| 219 | 234 | if ( 'divider' === $this->field->type ) { |
| 220 | 235 | $this->section_is_open = true; |
| 221 | 236 | } |
| 222 | 237 | |
| 223 | - if ( ! empty( $this->section_helper ) ) { | |
| 238 | + if ( $this->section_helper ) { | |
| 224 | 239 | $this->section_helper->sync_list_size(); |
| 225 | 240 | |
| 226 | 241 | if ( 'end_divider' === $this->field->type ) { |
| 227 | 242 | $this->maybe_close_section_helper(); |
| 228 | 243 | } |
| 244 | + | |
| 229 | 245 | return; |
| 230 | 246 | } |
| 231 | 247 | |
| 232 | - if ( false !== $this->parent_li ) { | |
| 233 | - ++$this->current_field_count; | |
| 234 | - $this->current_list_size += $this->active_field_size; | |
| 248 | + if ( false === $this->parent_li ) { | |
| 249 | + return; | |
| 250 | + } | |
| 235 | 251 | |
| 236 | - if ( 12 === $this->current_list_size ) { | |
| 237 | - $this->close_field_wrapper(); | |
| 238 | - } | |
| 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(); | |
| 239 | 257 | } |
| 240 | 258 | } |
| 241 | 259 | |
| 242 | 260 | /** |
| @@ -254,9 +272,14 @@ | ||
| 254 | 272 | /** |
| 255 | 273 | * @return void |
| 256 | 274 | */ |
| 257 | 275 | private function close_field_wrapper() { |
| 258 | - $this->maybe_close_section_helper(); | |
| 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 | + | |
| 259 | 282 | echo '</ul></li>'; |
| 260 | 283 | $this->parent_li = false; |
| 261 | 284 | $this->current_list_size = 0; |
| 262 | 285 | $this->current_field_count = 0; |