From 5d0609b46f81e5d3a8cf826ca5228acf18a07445 Mon Sep 17 00:00:00 2001 From: Clement Boirie Date: Thu, 13 Jul 2023 17:43:09 +0200 Subject: [PATCH] feat(default-facetwp): add default for FacetWP --- default-facetwp-a11y.php | 137 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 default-facetwp-a11y.php diff --git a/default-facetwp-a11y.php b/default-facetwp-a11y.php new file mode 100644 index 0000000..47bcc5a --- /dev/null +++ b/default-facetwp-a11y.php @@ -0,0 +1,137 @@ + 1, + 'per_page' => 10, + 'total_rows' => 1, + ]; + $params = array_merge( $defaults, $params ); + $output = ''; + $page = (int) $params['page']; + $total_pages = (int) $params['total_pages']; + + // Only show pagination when > 1 page + if ( 1 < $total_pages ) { + + $text_page = esc_html__( 'Page', 'fwp-front' ); + $text_of = esc_html__( 'of', 'fwp-front' ); + $step = 10; + + $output .= '' . "$text_page $page $text_of $total_pages"; + + if ( $page > 1 ) { + $output .= ''; + } else { + $output .= ''; + } + + if ( 3 < $page ) { + $output .= ' + Première page + + '; + } + if ( 1 < ( $page - $step ) ) { + $output .= ''; + } + + for ( $i = 2; $i > 0; $i -- ) { + if ( 0 < ( $page - $i ) ) { + $output .= 'Page ' . ( $page - $i ) . ''; + } + } + + // Current page + $output .= 'Page courante ' . $page . ''; + + for ( $i = 1; $i <= 2; $i ++ ) { + if ( $total_pages >= ( $page + $i ) ) { + $output .= 'Page ' . ( $page + $i ) . ''; + } + } + + if ( $total_pages > ( $page + $step ) ) { + $output .= ''; + } + + if ( $total_pages > ( $page + 2 ) ) { + $output .= ' + Dernière page + + '; + } + + if ( $page < $total_pages && $total_pages > 1 ) { + $output .= ''; + } else { + $output .= ''; + } + } + + return $output; +} + +/** + * Fix Labels for supported facets. + * Put in show_label_not_empty the facets that only need to be visible in they have results. + * + * @param string $html + * @param array $args + * + * @return string + */ +function accessible_facetwp_labels( string $html, array $args ): string { + $show_label_not_empty = [ + 'checkboxes', + 'radio', + ]; + + if ( ( true === in_array( $args['facet']['type'], $show_label_not_empty, true ) && ! empty( $args['values'] ) ) || false === in_array( $args['facet']['type'], $show_label_not_empty, true ) ) { + $html = sprintf( '%s', esc_attr( $args['facet']['name'] ), esc_html( $args['facet']['label'] ), $html ); + } + + return $html; +}