Merge pull request #773 from woocommerce/pcp-515-tabs

Render sections as tabs instead of links
This commit is contained in:
Emili Castells 2022-08-10 09:16:28 +02:00 committed by GitHub
commit 8f16fb92aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View file

@ -56,14 +56,12 @@ class SectionsRenderer {
/** /**
* Renders the Sections tab. * Renders the Sections tab.
*/ */
public function render(): void { public function render(): string {
if ( ! $this->should_render() ) { if ( ! $this->should_render() ) {
return; return '';
} }
echo '<ul class="subsubsub">'; $html = '<nav class="nav-tab-wrapper woo-nav-tab-wrapper">';
$array_keys = array_keys( $this->sections );
foreach ( $this->sections as $id => $label ) { foreach ( $this->sections as $id => $label ) {
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $id ); $url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . $id );
@ -73,9 +71,11 @@ class SectionsRenderer {
// Other gateways render fields differently, and their pages are not expected to work when gateway is not available. // Other gateways render fields differently, and their pages are not expected to work when gateway is not available.
$url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&' . self::KEY . '=' . $id ); $url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&' . self::KEY . '=' . $id );
} }
echo '<li><a href="' . esc_url( $url ) . '" class="' . ( $this->page_id === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a> ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' </li>'; $html .= '<a href="' . esc_url( $url ) . '" class="nav-tab ' . ( $this->page_id === $id ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a> ';
} }
echo '</ul><br class="clear" />'; $html .= '</nav>';
return $html;
} }
} }

View file

@ -66,13 +66,12 @@ class WCGatewayModule implements ModuleInterface {
'woocommerce_sections_checkout', 'woocommerce_sections_checkout',
function() use ( $c ) { function() use ( $c ) {
$section_renderer = $c->get( 'wcgateway.settings.sections-renderer' ); $section_renderer = $c->get( 'wcgateway.settings.sections-renderer' );
/** assert( $section_renderer instanceof SectionsRenderer );
* The Section Renderer.
* // phpcs:ignore WordPress.Security.EscapeOutput
* @var SectionsRenderer $section_renderer echo $section_renderer->render();
*/ },
$section_renderer->render(); 20
}
); );
add_action( add_action(