Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions public/app/themes/clarity/agency-switcher.php
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();
9 changes: 9 additions & 0 deletions public/app/themes/clarity/inc/agency.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ public function getList()
return $agencies_array;
}

/*
* Check if the agency cookie is set
*/
public function hasAgencyCookie(): bool
{
$agencyCookie = $_COOKIE['dw_agency'] ?? '';
return (bool)$agencyCookie;
}
Copy link
Contributor

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'])


/***
* Get the agency from cookie, and make sure it's in
* the list, otherwise default to HQ
Expand Down
20 changes: 16 additions & 4 deletions public/app/themes/clarity/inc/cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@
// a dw_agency cookie does not exist
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

  • returning around line 37.
  • removing the else clause.

} 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'
Copy link
Contributor

Choose a reason for hiding this comment

The 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 wp/wp-admin....

You could use some WP functions to be more robust, there are three that might be worth using in this Stack Overflow comment.

is_admin, wp_doing_ajax & wp_doing_cron.

)
{
// Redirect to the agency switcher page
wp_safe_redirect('/agency-switcher/');
exit;
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@

.c-header-container {
margin-bottom: $spacing;

&--underlined {
border-bottom: 10px solid $defaultAgencyColour;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<header class="c-header-container" role="banner">
<?php

use MOJ\Intranet\Agency;

$oAgency = new Agency();

// Show a simplified header if the user has not yet chosen an agency
$simpleHeader = !$oAgency->hasAgencyCookie();

?>
<header class="c-header-container<?= $simpleHeader ? " c-header-container--underlined" : ""?>" role="banner">

<?php
// Hide the search bar and main nav bar if hideHeader is set, e.g. on first login before the user has chosen an agency
get_template_part('src/components/c-logo-bar/view');
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
?>

if (!$simpleHeader) {
get_template_part('src/components/c-search-bar/view');
get_template_part('src/components/c-main-nav-bar/view');
}
?>
<!--[if lte IE 9]>
<div class="u-message u-message--warning">
You are using an old browser that may impact your web browsing experience. It is recommended you switch to use Firefox or a modern version of Internet Explorer if possible.
Expand Down
10 changes: 8 additions & 2 deletions public/app/themes/clarity/src/components/c-logo-bar/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

$oAgency = new Agency();
$activeAgency = $oAgency->getCurrentAgency();

// Show a simplified header if the user has not yet chosen an agency
$simpleHeader = !$oAgency->hasAgencyCookie();

$header_logo = get_field(get_intranet_code() .'_header_logo', 'option');
$logo = get_stylesheet_directory_uri() . '/dist/images/moj_logo_header.png';

Expand All @@ -24,13 +28,15 @@
<div class="u-wrapper__stack--left">
<a href="/" rel="home">
<img class="c-logo-bar__logo" aria-hidden="true" src="<?= $logo ?>" alt="" />
<span class="agency-title l-half-section"><?= $activeAgency['label'] ?></span>
<!-- We hide the full header if the user hasn't selected an agency -->
<!-- Default to 'Ministry of Justice' in the logo bar in this case -->
<span class="agency-title l-half-section"><?= $simpleHeader ? 'Ministry of Justice' : $activeAgency['label'] ?></span>
</a>
</div>

<div class="u-wrapper__stack--right">
<?php if (get_query_var('name') !== 'agency-switcher') : ?>
<a href="/agency-switcher" class="c-logo-bar__switch">Switch to other intranet</a>
<a href="/agency-switcher" class="c-logo-bar__switch"><?= $simpleHeader ? 'Choose an agency' : 'Switch to other intranet' ?></a>
<?php endif; ?>
</div>
</div>
Expand Down
Loading