Skip to content

Commit

Permalink
Merge pull request #619 from NHSLeadership/develop
Browse files Browse the repository at this point in the history
v2.5.4
  • Loading branch information
maheshmuralip authored Feb 5, 2024
2 parents 300192f + a4ede78 commit 1ceea78
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 260 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nightingale 2.5.3
<img src="https://img.shields.io/badge/nightingale-v2.5.3-blue">
# Nightingale 2.5.4
<img src="https://img.shields.io/badge/nightingale-v2.5.4-blue">
<a href="https://github.com/nhsuk/nhsuk-frontend">
<img src="https://img.shields.io/badge/nhsuk--frontend-v6.1.0-blue"></a> <a href="https://www.gnu.org/licenses/gpl-3.0.en.html"><img src="https://img.shields.io/badge/license-GPL%20(%3E%3D3)-green"></a> <a href="https://wordpress.org"><img src="https://img.shields.io/badge/WordPress-v5.5%20%2B-lightgrey"></a> <img src="https://img.shields.io/badge/php-5.6%2B-red"> <img src="https://img.shields.io/badge/pull%20requests-welcome-blueviolet"> <a href="https://wordpress.org/themes/nightingale"><img src="https://img.shields.io/badge/theme%20install-WP%20repo-lightgrey"></a>

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nhsleadership/nightingale",
"version": "2.5.3",
"version": "2.5.4",
"description": " NHSUK Frontend style theme for WordPress",
"repositories":[{"type":"composer","url":"https://wpackagist.org"}],
"type": "wordpress-theme",
Expand Down
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://developer.wordpress.org/themes/basics/theme-functions/
* @package Nightingale
* @copyright NHS Leadership Academy, Tony Blacker
* @version 2.5.3 28 nov 2023
* @version 2.5.4 29 jan 2024
*/

/**
Expand Down
100 changes: 93 additions & 7 deletions inc/gravity-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,106 @@ function ( $form_string, $form ) {
// Style last page button.
$form_string = str_replace( 'button gform_button gform_last_page_button', 'nhsuk-button nhsuk-button--reverse', $form_string ); // For Gravity Forms version 2.7+.
// Style the save and continue functionality.
$form_string = str_replace( 'gform_save_link button', 'nhsuk-button nhsuk-button--secondary', $form_string );
$form_string = str_replace( 'gform_save_link', 'nhsuk-button nhsuk-button--secondary', $form_string );
$outerfind[] = 'gfield ';
$outerreplace[] = 'gfield nhsuk-form-group ';
$form_string = str_replace( 'gform_save_link button', 'nhsuk-button nhsuk-button--secondary', $form_string );
$form_string = str_replace( 'gform_save_link', 'nhsuk-button nhsuk-button--secondary', $form_string );

$outerfind[] = 'gfield_error';
$outerreplace[] = 'gfield_error nhsuk-form-group--error';
$form_string = str_replace( $outerfind, $outerreplace, $form_string );

$form_string = add_nhsuk_class( $form_string ); // Add 'nhsuk-form-group' to 'gfield'.
return $form_string;
},
10,
2
);

/**
* Str_replace was replacing every 'gfield' in the input box to 'gfield nhsuk-form-group'.
* For example, an address '10 springfield road' was convereting into '10 springfield nhsuk-form-group'.
* This method used php DOMDocument() to do the replacement.
*
* @param string $form_string the rendered html output of a GF.
* @param string $additional Additional class to append.
* @return string
*/
function add_nhsuk_class( $form_string, $additional = '' ) {
global $wp_version;
if ( (float) $wp_version >= 6.2 ) {
$form_string = add_nhsuk_class_with_tag_processor( $form_string, $additional = '' );
return $form_string;
} else {
$form_string = add_nhsuk_class_with_dom( $form_string, $additional = '' );
return $form_string;
}

}

/**
* This method uses WP html tag processor to add nhsuk class.
*
* @param string $form_string the rendered html output of a GF.
* @param string $additional Additional class to append.
* @return string
*/
function add_nhsuk_class_with_tag_processor( $form_string, $additional = '' ) {
$form_string = new \WP_HTML_Tag_Processor( $form_string );
$query = array(
'class_name' => 'gfield',
);
$class_name = 'nhsuk-form-group';
if ( ! empty( $additional ) ) {
$class_name = $class_name . ' ' . $additional;
}
while ( $form_string->next_tag( $query ) ) {
$form_string->add_class( $class_name );
}
return $form_string->get_updated_html();
}


/**
* This method used php DOMDocument() to add nhsuk class.
*
* @param string $html_text the rendered html output of a GF.
* @param string $additional Additional class to append.
* @return string
*/
function add_nhsuk_class_with_dom( $html_text, $additional = '' ) {
// Enable internal error handling mode to stop libxml errors display in the browser.
libxml_use_internal_errors( true );

$dom = new DOMDocument();
// Load HTML into the DOMDocument.
$dom->loadHTML( $html_text, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );

// Create a DOMXPath object to query the DOMDocument.
$xpath = new DOMXPath( $dom );

// Replace the class name.
$gfield_class = 'gfield ';
$nhsuk_class = 'nhsuk-form-group';
if ( ! empty( $additional ) ) {
$nhsuk_class = $nhsuk_class . ' ' . $additional;
}
// Find elements with the old class name.
$elements = $xpath->query( "//*[contains(@class, '$gfield_class')]" );
// Loop through the found elements and replace the class name.
foreach ( $elements as $element ) {
$class_attr = $element->getAttribute( 'class' );
$element->setAttribute(
'class',
$class_attr . ' ' . $nhsuk_class
);
}

libxml_use_internal_errors( false );

// Get the modified HTML.
return $dom->saveHTML();
}



// Use gform_field_content to style individual fields.
// See https://docs.gravityforms.com/gform_field_content.
add_filter( 'gform_field_content', 'nightingale_clean_gf_inputs', 12, 5 );
Expand Down Expand Up @@ -339,8 +425,8 @@ function nightingale_clean_gf_inputs( $field_content, $field, $value, $lead_id,
} else {
$outererror = '';
}
$outerfind[] = 'gfield ';
$outerreplace[] = 'gfield nhsuk-form-group ' . $outererror;
$field_content = add_nhsuk_class( $field_content, $outererror ); // Add 'nhsuk-form-group' to 'gfield'.

// reverse the logic of required highlighting - instead highlight only the optional fields.
if ( true !== $field->isRequired ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$outerfind[] = '</label>';
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
* @package Nightingale
* @copyright NHS Leadership Academy, Tony Blacker
* @version 2.5.3 28th November 2023
* @version 2.5.4 29th January 2024
*/

get_header();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/NHSLeadership/nightingale-2-0.git"
},
"version": "2.5.3",
"version": "2.5.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Requires PHP: 5.6
License: GPL v3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
Theme URI: https://digital.leadershipacademy.nhs.uk/digital-capabilities/websites/nightingale-theme-user-guide/
Version: 2.5.3
Version: 2.5.4
Stable tag: 2.5


Expand Down Expand Up @@ -43,6 +43,9 @@ one level only. To show further levels, we recommend using the right (or left) h

== Changelog

=2.5.4=
* Fix for gravity form css class conversion to nhsuk

=2.5.3=
* Fix for body class loading in admin

Expand Down
Loading

0 comments on commit 1ceea78

Please sign in to comment.