-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDPT-1939: Splash page #800
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
<?php | ||
|
||
use MOJ\Intranet\Agency; | ||
|
||
/* | ||
* Agency switcher | ||
*/ | ||
get_header(); | ||
?> | ||
|
||
<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main"> | ||
<h1 class="o-title o-title--page">Choose your agency or body</h1> | ||
<p>Other agencies and bodies have their own specific intranet content available to view by visiting the links below. HMPPS and YJB links are external intranet websites not managed by this central MoJ intranet.</p> | ||
<?php get_template_part('src/components/c-intranet-switcher/view'); ?> | ||
</main> | ||
$oAgency = new Agency(); | ||
$simpleHeader = !$oAgency->hasAgencyCookie(); | ||
|
||
$heading = 'Choose your agency or body'; | ||
$body = 'Other agencies and bodies have their own specific intranet content available to view by visiting the links | ||
below. HMPPS and YJB links are external intranet websites not managed by this central MoJ intranet.'; | ||
|
||
// If we're using the simple header, assume a new user and change the intro text to reflect this | ||
if ($simpleHeader) { | ||
$heading = 'Welcome to the Ministry of Justice intranet'; | ||
$body = 'Please choose your agency or body to access the intranet content specific to your organisation.'; | ||
} | ||
?> | ||
<main id="maincontent" class="u-wrapper l-main t-agency-switcher" role="main"> | ||
<h1 class="o-title o-title--page"> | ||
<?= $heading ?> | ||
</h1> | ||
<p> | ||
<?= $body ?> | ||
</p> | ||
<?php get_template_part('src/components/c-intranet-switcher/view'); ?> | ||
</main> | ||
<?php | ||
get_footer(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,10 +38,22 @@ | |
// a dw_agency cookie does not exist | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if this is really annoying... I think this is a good opportunity to make this function easier to read. What do you think about the following pattern?
|
||
} else { | ||
$agency = $_COOKIE['dw_agency'] ?? ''; | ||
|
||
if (!$agencies->agencyExists($agency)) { | ||
setcookie('dw_agency', $agency_default, $options); | ||
$_COOKIE['dw_agency'] = $agency_default; | ||
$slug = get_post_field('post_name'); | ||
|
||
if ( | ||
// If the agency cookie isn't set or is set to an invalid agency | ||
!$agencies->agencyExists($agency) && | ||
// And the current page isn't the agency switcher, privacy notice, or accessibility page | ||
!in_array($slug, ['agency-switcher', 'privacy-notice', 'accessibility'], true) && | ||
// And the user isn't logged in | ||
!is_user_logged_in() && | ||
// And we're not in the admin area | ||
$_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a good check to have, but I don't think it's working as intended, because our admin paths start with You could use some WP functions to be more robust, there are three that might be worth using in this Stack Overflow comment.
|
||
) | ||
{ | ||
// Redirect to the agency switcher page | ||
wp_safe_redirect('/agency-switcher/'); | ||
exit; | ||
} | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is opinionated, just for your consideration :)
empty()
might be a good alternative to use here, as it matches an unset value or an empty string.e.g.
return !empty($_COOKIE['dw_agency'])