diff --git a/localgov_base.theme b/localgov_base.theme index 3ea68d10..b2fc5a58 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -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; + } + } + } /** diff --git a/templates/layout/status-pages/page--403.html.twig b/templates/layout/status-pages/page--403.html.twig index b01f7b4c..6fe25950 100644 --- a/templates/layout/status-pages/page--403.html.twig +++ b/templates/layout/status-pages/page--403.html.twig @@ -1 +1,10 @@ +{% if default_status_content %} + {% set default_status_content %} +

{{ "Sorry, you do not have access to this page"|t }}

+ {% trans %} +

Perhaps you need to log in to the site.

+ {% endtrans %} + {% endset %} +{% endif %} + {% extends "@localgov_base/layout/status-pages/page-status.html.twig" %} diff --git a/templates/layout/status-pages/page--404.html.twig b/templates/layout/status-pages/page--404.html.twig index b01f7b4c..c7073fc9 100644 --- a/templates/layout/status-pages/page--404.html.twig +++ b/templates/layout/status-pages/page--404.html.twig @@ -1 +1,10 @@ +{% if default_status_content %} + {% set default_status_content %} +

{{ "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 }}

+

{{ "If you typed the web address, check it is correct."|t }}

+

{{ "If you pasted the web address, check you copied the entire address."|t }}

+

{{ "You can browse from the homepage or use the search box above to find the information you need."|t }}

+ {% endset %} +{% endif %} + {% extends "@localgov_base/layout/status-pages/page-status.html.twig" %} diff --git a/templates/layout/status-pages/page-status.html.twig b/templates/layout/status-pages/page-status.html.twig index 257735a3..0a907f2c 100644 --- a/templates/layout/status-pages/page-status.html.twig +++ b/templates/layout/status-pages/page-status.html.twig @@ -113,6 +113,7 @@
+ {{ default_status_content }} {{ page.content }}