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

adds default content for 403 and 404 pages #699

Merged
merged 6 commits into from
Feb 11, 2025
Merged
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
33 changes: 33 additions & 0 deletions localgov_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ function localgov_base_preprocess_page(&$variables): void {
if (theme_get_setting('localgov_base_show_back_to_top_link')) {
$variables['back_to_top'] = TRUE;
}

// Load the site configuration.
$site_config = \Drupal::config('system.site');
$site_403 = $site_config->get('page.403');
$site_404 = $site_config->get('page.404');

// Custom 403 and 404 pages.
// We have a variable in page.html.twig called default_status_content.
// This is used to determine if we should show the default 403/404 content,
// or if we should show the content of the node that is set as the 403/404
// page.
$variables['default_status_content'] = TRUE;
$route_match = Drupal::routeMatch();
$route = $route_match->getRouteName();
if ($route === 'entity.node.canonical') {
$node = $route_match->getParameter('node');
$node_id = $node->id();
$is_404_page_node = $site_404 === 'node/' . $node_id;
$is_403_page_node = $site_403 === 'node/' . $node_id;
if ($is_404_page_node && is_null($site_404)) {
$variables['default_status_content'] = TRUE;
}
else {
$variables['default_status_content'] = FALSE;
}
if ($is_403_page_node && is_null($site_403)) {
$variables['default_status_content'] = TRUE;
}
else {
$variables['default_status_content'] = FALSE;
}
}

}

/**
Expand Down
9 changes: 9 additions & 0 deletions templates/layout/status-pages/page--403.html.twig
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{% if default_status_content %}
{% set default_status_content %}
<p>{{ "Sorry, you do not have access to this page"|t }}</p>
{% trans %}
<p>Perhaps you need to <a href="/user/login">log in</a> to the site.</p>
{% endtrans %}
{% endset %}
{% endif %}

{% extends "@localgov_base/layout/status-pages/page-status.html.twig" %}
9 changes: 9 additions & 0 deletions templates/layout/status-pages/page--404.html.twig
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{% if default_status_content %}
{% set default_status_content %}
<p>{{ "We couldn't find the page you're looking for. It's possible you entered the address incorrectly or you're looking for a page we've moved or deleted."|t }}</p>
<p>{{ "If you typed the web address, check it is correct."|t }}</p>
<p>{{ "If you pasted the web address, check you copied the entire address."|t }}</p>
<p>{{ "You can browse from the homepage or use the search box above to find the information you need."|t }}</p>
{% endset %}
{% endif %}

{% extends "@localgov_base/layout/status-pages/page-status.html.twig" %}
1 change: 1 addition & 0 deletions templates/layout/status-pages/page-status.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<div class="lgd-row">
<div class="lgd-row__full">
<div class="padding-horizontal">
{{ default_status_content }}
{{ page.content }}
</div>
</div>
Expand Down