Skip to content

Commit 9b72e2a

Browse files
arraypressclaude
andcommitted
Honour tab and accordion markers on a settings page
Same as the metabox: this class builds its own form-table and asks the kit for one control at a time, so a `tab` or `accordion` field reached it as an ordinary field and drew nothing. Splitting happens per settings section, which is also what makes one of each possible on a screen: the first marker decides the kind for the list it divides, so tabs and accordions have to be in separate sections. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tk8y5eZa3CHVVSM6nVxsJw
1 parent 9904f04 commit 9b72e2a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎src/SettingFields.php‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ArrayPress\FieldKit\Field;
2222
use ArrayPress\FieldKit\FieldSet;
2323
use ArrayPress\FieldKit\Support\Badge;
24+
use ArrayPress\FieldKit\Support\Sections;
2425
use ArrayPress\FieldKit\Support\Tooltip;
2526
use ArrayPress\FieldKit\Support\PageHeader;
2627

@@ -680,9 +681,49 @@ private function render_sections( string $tab ): void {
680681
* @return void
681682
*/
682683
private function render_table( FieldSet $set, array $fields ): void {
684+
$layout = Sections::split( $fields );
685+
686+
if ( [] !== $layout ) {
687+
$sections = Sections::render(
688+
$layout,
689+
function ( array $group ) use ( $set ): string {
690+
if ( [] === $group ) {
691+
return '';
692+
}
693+
694+
ob_start();
695+
$this->render_rows( $set, $group );
696+
697+
return (string) ob_get_clean();
698+
},
699+
$this->id . '-' . count( $fields )
700+
);
701+
702+
echo $sections; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped as it is built.
703+
704+
return;
705+
}
706+
707+
$this->render_rows( $set, $fields );
708+
}
709+
710+
/**
711+
* A set of fields as one settings table.
712+
*
713+
* @param FieldSet $set The field set.
714+
* @param Field[] $fields The fields to render.
715+
*
716+
* @return void
717+
*/
718+
private function render_rows( FieldSet $set, array $fields ): void {
683719
echo '<table class="form-table" role="presentation"><tbody>';
684720

685721
foreach ( $fields as $field ) {
722+
// A marker draws nothing, so one left in emits an empty row.
723+
if ( Sections::is_marker( $field ) ) {
724+
continue;
725+
}
726+
686727
$type = $field->type();
687728

688729
// A heading, a notice or a separator is not a control, and an

0 commit comments

Comments
 (0)