Skip to content

Commit

Permalink
Merge pull request #389 from NHSLeadership/v2.3.1-final-release-checks
Browse files Browse the repository at this point in the history
V2.3.1 final release checks
  • Loading branch information
tblacker7 authored Feb 4, 2021
2 parents 9446085 + 0b9c787 commit 3f9ba18
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 108 deletions.
27 changes: 14 additions & 13 deletions inc/breadcrumbs.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
<?php
/**
* Generate breadcrumbs
*
* Get path to current page and leave breacrumb trail for users to navigate back up the decision tree
*
* @link https://developer.wordpress.org/themes/basics/template-files/
*
* @package Nightingale
* @link https://developer.wordpress.org/themes/basics/template-files/
* @package Nightingale
* @copyright NHS Leadership Academy, Tony Blacker
* @version 1.1 21st August 2019
* @version 1.1 21st August 2019
*/

/**
* Create the breadcrumb
*
* @param int $id Post id of the page being queried.
* @param boolean $link Should current page be linked or not.
* @param int $id Post id of the page being queried.
* @param boolean $link Should current page be linked or not.
* @param string $separator Add any fancy separators.
* @param string $nicename Clean up the name or not.
* @param array $visited Has this page been visited.
* @param boolean $iscrumb Is this to be added to the breadcrumb.
* @param string $nicename Clean up the name or not.
* @param array $visited Has this page been visited.
* @param boolean $iscrumb Is this to be added to the breadcrumb.
*
* @return array $chain
*/
Expand All @@ -45,6 +43,7 @@ function nightingale_category_parents( $id, $link = false, $separator = '', $nic
} else {
$chain .= '<li class="nhsuk-breadcrumb__item">' . $name . $separator . '</li>';
}

return $chain;
}

Expand Down Expand Up @@ -87,9 +86,9 @@ function nightingale_breadcrumb() {
if ( true === nightingale_uncanny_breadcrumb_check() ) {
$breadcrumbs = uo_breadcrumbs( false );
} else {
$back_one_level = empty( $back_one_level ) ? array( esc_url( home_url() ), __( 'Home', 'nightingale' ) ) : $back_one_level;
$back_one_level = empty( $back_one_level ) ? array( esc_url( home_url() ), __( 'Home', 'nightingale' ) ) : $back_one_level;
list( $trail, $back_one_level ) = nightingale_breadcrumb_trail();
$breadcrumbs = sprintf(
$breadcrumbs = sprintf(
'<ol class="nhsuk-breadcrumb__list"><li class="nhsuk-breadcrumb__item"><a href="%2$s">%3$s</a></li>%1$s</ol>',
$trail,
esc_url( home_url() ),
Expand Down Expand Up @@ -121,6 +120,7 @@ function nightingale_breadcrumb() {
);

$output = ob_get_clean();

return $output;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ function nightingale_breadcrumb_trail() {
$home_page = get_option( 'page_on_front' );
foreach ( $ancestors as $ancestor ) {
if ( ( end( $ancestors ) !== $ancestor ) && ( ( $home_page !== $ancestor ) ) ) {
$trail .= '<li class="nhsuk-breadcrumb__item"> <a href="' . esc_url( get_permalink( $ancestor ) ) . '">' . esc_html( wp_strip_all_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) ) . '</span></a></li>';
$trail .= '<li class="nhsuk-breadcrumb__item"> <a href="' . esc_url( get_permalink( $ancestor ) ) . '">' . esc_html( wp_strip_all_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) ) . '</span></a></li>';
$back_one_level = array(
esc_url( get_permalink( $ancestor ) ),
wp_strip_all_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ),
Expand All @@ -189,5 +189,6 @@ function nightingale_breadcrumb_trail() {
if ( ! ( is_archive() || is_category() || is_post_type_archive() || is_search() || is_404() || is_singular( 'tribe_events' ) ) ) {
$trail .= '<li class="nhsuk-breadcrumb__item current">' . esc_html( get_the_title() ) . '</li>';
}

return array( apply_filters( 'nightingale_modify_breadcrumb', $trail ), $back_one_level );
}
133 changes: 66 additions & 67 deletions inc/gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@
* @package Nightingale Theme
*/


add_filter(
'gform_get_form_filter',
function ( $form_string, $form ) {
// Replace form description span with <nhsuk-hint> elements.
$form_string = preg_replace( "#<span class='gform_description'>(.*?)</span>#", '<span class="nhsuk-hint">$1</span>', $form_string );
// Style error messages.
// Message at top of form.
$form_string = str_replace( 'validation_error', 'nhsuk-error-message is-error', $form_string );
// Fields with CSS class = "gfield_error".
$form_string = str_replace( 'gfield_error', 'is-error gfield_error', $form_string );
// Fields contained in <li> elements that have CSS class = "gfield_error".
$form_string = preg_replace( "#<li(.*?)gfield_error(.*?)<input(.*?)class='#s", "<li$1gfield_error$2<input$3class='gfield_error is-error ", $form_string );
// Error messages below fields.
$form_string = str_replace( 'validation_message', 'nhsuk-u-visually-hidden validation_message', $form_string );
// Style <ul>.
$form_string = str_replace( "class='gform_fields", "class='c-form-list gform_fields", $form_string );
// Replace <h3> with <h2>.
$form_string = str_replace( '<h3', '<h2', $form_string );
$form_string = str_replace( '/h3>', '/h2>', $form_string );
// Replace field description divs with <small> elements.
$form_string = preg_replace( "#<div class='gfield_description'(.*?)</div>#", "<span class='nhsuk-hint'$1</span>", $form_string );
// Replace field instruction divs with <small> elements.
$form_string = preg_replace( "#<div class='instruction(.*?)>(.*?)</div>#", '<small>$2</small>', $form_string );
// Remove "required" tag NHSUK Service manual insted recommends highlighting optional fields, which is done elsewhere.
$form_string = str_replace( "<span class='gfield_required'>*</span>", '', $form_string );
// Replace main gfield_label elements with nhsuk-label.
$form_string = preg_replace( '#gfield_label#s', 'nhsuk-label', $form_string );
// Remove <ul>s around elements.
$form_string = preg_replace( "#<ul class='gfield(.*?)>(.*?)</ul>#s", '$2', $form_string );
// Add nhsuk-form-group to form <li> elements.
$form_string = preg_replace( "#<li(.*?)field_(.*?)class='(.*?)#m", "<li$1field_$2class='nhsuk-form-group $3", $form_string );
// Style the submit button.
$form_string = str_replace( 'gform_button', 'nhsuk-button gform_button', $form_string );
// Style the save and continue functionality.
$form_string = preg_replace( "#<a (.*?)class='gform_save_link' (.*?)</a>#", "<a $1 class='nhsuk-button nhsuk-button--secondary gform_save_link' $2</a>", $form_string );
return $form_string;
},
10,
2
);
add_filter(
'gform_get_form_filter',
function ( $form_string, $form ) {
// Replace form description span with <nhsuk-hint> elements.
$form_string = preg_replace( "#<span class='gform_description'>(.*?)</span>#", '<span class="nhsuk-hint">$1</span>', $form_string );
// Style error messages.
// Message at top of form.
$form_string = str_replace( 'validation_error', 'nhsuk-error-message is-error', $form_string );
// Fields with CSS class = "gfield_error".
$form_string = str_replace( 'gfield_error', 'is-error gfield_error', $form_string );
// Fields contained in <li> elements that have CSS class = "gfield_error".
$form_string = preg_replace( "#<li(.*?)gfield_error(.*?)<input(.*?)class='#s", "<li$1gfield_error$2<input$3class='gfield_error is-error ", $form_string );
// Error messages below fields.
$form_string = str_replace( 'validation_message', 'nhsuk-u-visually-hidden validation_message', $form_string );
// Style <ul>.
$form_string = str_replace( "class='gform_fields", "class='c-form-list gform_fields", $form_string );
// Replace <h3> with <h2>.
$form_string = str_replace( '<h3', '<h2', $form_string );
$form_string = str_replace( '/h3>', '/h2>', $form_string );
// Replace field description divs with <small> elements.
$form_string = preg_replace( "#<div class='gfield_description'(.*?)</div>#", "<span class='nhsuk-hint'$1</span>", $form_string );
// Replace field instruction divs with <small> elements.
$form_string = preg_replace( "#<div class='instruction(.*?)>(.*?)</div>#", '<small>$2</small>', $form_string );
// Remove "required" tag NHSUK Service manual insted recommends highlighting optional fields, which is done elsewhere.
$form_string = str_replace( "<span class='gfield_required'>*</span>", '', $form_string );
// Replace main gfield_label elements with nhsuk-label.
$form_string = preg_replace( '#gfield_label#s', 'nhsuk-label', $form_string );
// Remove <ul>s around elements.
$form_string = preg_replace( "#<ul class='gfield(.*?)>(.*?)</ul>#s", '$2', $form_string );
// Add nhsuk-form-group to form <li> elements.
$form_string = preg_replace( "#<li(.*?)field_(.*?)class='(.*?)#m", "<li$1field_$2class='nhsuk-form-group $3", $form_string );
// Style the submit button.
$form_string = str_replace( 'gform_button', 'nhsuk-button gform_button', $form_string );
// Style the save and continue functionality.
$form_string = preg_replace( "#<a (.*?)class='gform_save_link' (.*?)</a>#", "<a $1 class='nhsuk-button nhsuk-button--secondary gform_save_link' $2</a>", $form_string );

return $form_string;
},
10,
2
);

// Use gform_field_content to style individual fields.
// See https://docs.gravityforms.com/gform_field_content.
Expand All @@ -73,7 +73,7 @@ function nightingale_clean_gf_inputs( $field_content, $field ) {
$grouperror = '';
}
$label = '';
if ( ( 'html' !== $field->type ) && ( 'section' !== $field->type ) && ( 'radio' !== $field->type ) && ( 'address' !== $field->type ) && ( 'hidden_label' !== $field->labelPlacement ) && ( empty( $field->gsurveyLikertRows) ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( ( 'html' !== $field->type ) && ( 'section' !== $field->type ) && ( 'radio' !== $field->type ) && ( 'address' !== $field->type ) && ( 'hidden_label' !== $field->labelPlacement ) && ( empty( $field->gsurveyLikertRows ) ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$label .= '<label for="input_' . $field->formId . '_' . $field->id . '" class="nhsuk-label">' . $field->label; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( true !== $field->isRequired ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$label .= '&nbsp;&nbsp;<span class="nhsuk-tag">Optional</span>';
Expand Down Expand Up @@ -200,7 +200,7 @@ function nightingale_clean_gf_inputs( $field_content, $field ) {
if ( 1 === $errorflag ) {
$radiolabel .= '<span class="nhsuk-error-message">' . $field->validation_message . '</span>';
}
$radiolabel .= '<br/>';
$radiolabel .= '<br/>';
$find = "#<label class='gfield_label'(\s*?)>(.*?)</label>(.*?)<div(.*?)>(.*?)<ul class='gfield_radio' id='(.*?)'>(.*?)</ul></div>#";
$replace = "<fieldset class='ginput_container nhsuk-fieldset' id='$6'><legend class='nhsuk-fieldset__legend'>$2 $radiolabel</legend>$3<div class='nhsuk-radios'>$7</div></fieldset>";
$field_content = preg_replace( $find, $replace, $field_content );
Expand Down Expand Up @@ -232,31 +232,30 @@ function nightingale_clean_gf_inputs( $field_content, $field ) {
$find [] = "#<li class='(.*?)'><input(.*?)type='checkbox'(.*?)><label(.*?)</label></li>#i";
$replace[] = "<div class='nhsuk-checkboxes__item $1'><input $2 type='checkboxes' $3 class='nhsuk-checkboxes__input'><label class='nhsuk-label nhsuk-checkboxes__label' $4</label> </div>";
// likert sort out. This is messy.
// For accessibility add labels (for screen readers only) to survey radio buttons.
$likertlabel = '';
if ( true !== $field->isRequired ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$likertlabel .= '&nbsp;&nbsp;<span class="nhsuk-tag">Optional</span>';
}

if ( 1 === $errorflag ) {
$likertlabel .= '<span class="nhsuk-error-message">' . $field->validation_message . '</span>';
}
$likertlabel .= '<br/>';
$find[] = "#<label class='gfield_label'>(.*?)</label><div(.*?)><table class='gsurvey-likert'(.*?)><thead>(.*?)</thead><tbody>(.*?)</tbody></table></div>#"; // strip out all the table gunk.
$replace[] = "<fieldset class='gsurvey-likert nhsuk-fieldset'$2><legend class='nhsuk-fieldset__legend'>$1$likertlabel</legend><div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert'><div class='nhsuk-likert__row nhsuk-likert__header'>$4</div>$5</div></fieldset>"; // replace it with a much simpler div layout.
$find[] = "#<th(.*?)>(.*?)</th>#";
$replace[] = "<div class='nhsuk-radios__item nhsuk-likert__item'>$2</div>";
$find[] = "#<div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert'>(.*?)<tr><td(.*?)class='gsurvey-likert-row-label'>(.*?)</td>(.*?)</tr></div>#"; // identify multi row tables.
$replace[] = "<div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert nhsuk-likert__multi'>$1<tr><td$2 class='gsurvey-likert-row-label'>$3</td>$4</tr></div>";
$find[] = "#<tr><td(.*?)class='gsurvey-likert-row-label'>(.*?)</td>(.*?)</tr>#"; // modify multi row grids.
$replace[] = "<div class='nhsuk-likert__row'$1><div class='nhsuk-likert__item nhsuk-likert__rowlabel'>$2</div>$3</div>";
$find[] = "#<tr>(.*?)</tr>#"; // now mop up the single row grids.
$replace[] = "<div class='nhsuk-likert__row'>$1</div>";
// For accessibility add labels (for screen readers only) to survey radio buttons.
$likertlabel = '';
if ( true !== $field->isRequired ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$likertlabel .= '&nbsp;&nbsp;<span class="nhsuk-tag">Optional</span>';
}

$find[] = "#<td data-label='(.*?)' class='gsurvey-likert-choice'><input name='(.*?)' type='radio' value='(.*?)'id='(.*?)'/></td>#"; // we just have to pull out the td's now.
$replace[] = "<div data-label='$1' class='nhsuk-radios__item nhsuk-likert__item'><input name='$2' class='nhsuk-radios__input' type='radio' value='$3' id='$4'/><label class='nhsuk-label nhsuk-radios__label' for='$4'><span class='nhsuk-u-visually-hidden'>$1</span></label></div>"; // and turn them into pretty divs with nhsuk-radios.
if ( 1 === $errorflag ) {
$likertlabel .= '<span class="nhsuk-error-message">' . $field->validation_message . '</span>';
}
$likertlabel .= '<br/>';
$find[] = "#<label class='gfield_label'>(.*?)</label><div(.*?)><table class='gsurvey-likert'(.*?)><thead>(.*?)</thead><tbody>(.*?)</tbody></table></div>#"; // strip out all the table gunk.
$replace[] = "<fieldset class='gsurvey-likert nhsuk-fieldset'$2><legend class='nhsuk-fieldset__legend'>$1$likertlabel</legend><div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert'><div class='nhsuk-likert__row nhsuk-likert__header'>$4</div>$5</div></fieldset>"; // replace it with a much simpler div layout.
$find[] = '#<th(.*?)>(.*?)</th>#';
$replace[] = "<div class='nhsuk-radios__item nhsuk-likert__item'>$2</div>";
$find[] = "#<div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert'>(.*?)<tr><td(.*?)class='gsurvey-likert-row-label'>(.*?)</td>(.*?)</tr></div>#"; // identify multi row tables.
$replace[] = "<div class='nhsuk-radios nhsuk-radios--inline nhsuk-likert nhsuk-likert__multi'>$1<tr><td$2 class='gsurvey-likert-row-label'>$3</td>$4</tr></div>";
$find[] = "#<tr><td(.*?)class='gsurvey-likert-row-label'>(.*?)</td>(.*?)</tr>#"; // modify multi row grids.
$replace[] = "<div class='nhsuk-likert__row'$1><div class='nhsuk-likert__item nhsuk-likert__rowlabel'>$2</div>$3</div>";
$find[] = '#<tr>(.*?)</tr>#'; // now mop up the single row grids.
$replace[] = "<div class='nhsuk-likert__row'>$1</div>";
$find[] = "#<td data-label='(.*?)' class='gsurvey-likert-choice'><input name='(.*?)' type='radio' value='(.*?)'id='(.*?)'/></td>#"; // we just have to pull out the td's now.
$replace[] = "<div data-label='$1' class='nhsuk-radios__item nhsuk-likert__item'><input name='$2' class='nhsuk-radios__input' type='radio' value='$3' id='$4'/><label class='nhsuk-label nhsuk-radios__label' for='$4'><span class='nhsuk-u-visually-hidden'>$1</span></label></div>"; // and turn them into pretty divs with nhsuk-radios.

$field_content = preg_replace( $find, $replace, $field_content );
$field_content = preg_replace( $find, $replace, $field_content );
break;
// Name inputs.
case 'name':
Expand Down Expand Up @@ -363,7 +362,7 @@ function nightingale_gwp_days( $expiration_days ) {
* @return string
*/
function nightingale_change_upload_markup( $file_upload_markup, $file_info, $form_id, $field_id ) {
return '<strong>' . esc_html( $file_info[ 'uploaded_filename' ] ) . "</strong > <img class='gform_delete' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAABKUlEQVRYhe2Uuw4BQRSGPwqJW6KgU4jeA0jEC2h4Ku8hXkFJiCdYURJR0Ot0FM5kx2TZHTu7QvZPTjYzszP/d85cIFMme42AM3Az4gwM0wAIMldxSgNAmUXtf6tciJFLBXrlHZs410dltZn/9Qr8HIBZ0rC2cwDnygD+EmDvcjHbU78Dmlr7Qswn3RZAmavKdgUiNQCAPrAFWhqEqQYwBzpJAMyk76BBmOae/DNPAqAELKT/CLQN842MeUDdFiCqSjyy0yH0zCOZxwEAKANL/O2wylzpJJN6MSBW+IlsTPOwh2gi37W2SFhcgYHMKwI1bb0qULHJoACM8SthY17nec9VJV7dDqcKOnDvbodz81cHLhUIdf08gTFVwd+OZRIAHYEIMtchpkDrDvRKkk0dBvEBAAAAAElFTkSuQmCC'
return '<strong>' . esc_html( $file_info['uploaded_filename'] ) . "</strong > <img class='gform_delete' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAABKUlEQVRYhe2Uuw4BQRSGPwqJW6KgU4jeA0jEC2h4Ku8hXkFJiCdYURJR0Ot0FM5kx2TZHTu7QvZPTjYzszP/d85cIFMme42AM3Az4gwM0wAIMldxSgNAmUXtf6tciJFLBXrlHZs410dltZn/9Qr8HIBZ0rC2cwDnygD+EmDvcjHbU78Dmlr7Qswn3RZAmavKdgUiNQCAPrAFWhqEqQYwBzpJAMyk76BBmOae/DNPAqAELKT/CLQN842MeUDdFiCqSjyy0yH0zCOZxwEAKANL/O2wylzpJJN6MSBW+IlsTPOwh2gi37W2SFhcgYHMKwI1bb0qULHJoACM8SthY17nec9VJV7dDqcKOnDvbodz81cHLhUIdf08gTFVwd+OZRIAHYEIMtchpkDrDvRKkk0dBvEBAAAAAElFTkSuQmCC'
onclick='gformDeleteUploadedFile({$form_id}, {$field_id }, this)' alt='Delete this file' />";
}

Expand Down
Loading

0 comments on commit 3f9ba18

Please sign in to comment.