Skip to content

Commit 9e1c9c8

Browse files
committed
Draw the badge in the header cell
The renderer no longer emits one when the caller draws its own heading, because it was putting a pill hard against the side of every input. This screen draws every heading, so it draws every badge.
1 parent 18823a0 commit 9e1c9c8

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎src/SettingFields.php‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,21 @@ private function render_table( FieldSet $set, array $fields ): void {
683683
// A self-labelling control already carries its own <label for>,
684684
// and a group of controls has no single element to point at, so
685685
// both get plain text rather than a second label.
686+
// The badge belongs beside the heading, and the heading is here —
687+
// the renderer is told to draw none, so it draws no badge either.
688+
$badge = Badge::for_field( $field );
689+
686690
$header = $type->is_self_labelling() || $type->is_grouped()
687-
? sprintf( '<span class="field-kit__row-label">%s</span>', esc_html( $field->label() ) )
691+
? sprintf(
692+
'<span class="field-kit__row-label">%s%s</span>',
693+
esc_html( $field->label() ),
694+
$badge // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped as it is built.
695+
)
688696
: sprintf(
689-
'<label for="%s">%s</label>',
697+
'<label for="%s">%s</label>%s',
690698
esc_attr( $field->input_id() ),
691-
esc_html( $field->label() )
699+
esc_html( $field->label() ),
700+
$badge // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped as it is built.
692701
);
693702

694703
printf(

‎tests/SettingFieldsTest.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,15 @@ public function test_a_badged_section_locks_its_fields(): void {
653653

654654
$html = $this->render( $page );
655655

656-
// Once in the section heading, once on the field it locked.
656+
// Once in the section heading, once in the locked field's own header
657+
// cell — and not against the side of the input, which is where it
658+
// first went.
657659
$this->assertSame( 2, substr_count( $html, 'field-kit__badge' ) );
658660
$this->assertStringContainsString( 'field-kit__field--locked', $html );
661+
$this->assertMatchesRegularExpression(
662+
'/<th scope="row">.*field-kit__badge.*<\/th>/s',
663+
$html
664+
);
659665

660666
// And its stored value survives a save that cannot include it.
661667
$GLOBALS['fk_options']['sf_demo'] = [ 'locked' => 'set-while-licensed' ];

0 commit comments

Comments
 (0)