2

I have created a maintenance-page.html.twig template for my site.

The settings.php file says:

This applies when the site is explicitly set to maintenance mode through the administration page or when the database is inactive due to an error.

However, on my site, this only works if I explicitly turn on maintenance mode. If I intentionally break access to my database by changing the password I get a page with a PDO error, not my maintenance page.

Is this a bug, or am I missing something?

1

This looks to be the case of where the documentation is out-of-date. That comment has been around verbatim since D7. D8 doesn't produce a themed maintenance page like D7.

When looking at _drupal_log_error(), you can see that unless Drupal is going through the install process, a fatal error will output a bare error message with a 500 status then exit:

if ($fatal) {
  // We fallback to a maintenance page at this point, because the page generation
  // itself can generate errors.
  // Should not translate the string to avoid errors producing more errors.
  $message = 'The website encountered an unexpected error. Please try again later.' . '<br />' . $message;

  if ($is_installer) {
    // install_display_output() prints the output and ends script execution.
    $output = array(
      '#title' => 'Error',
      '#markup' => $message,
    );
    install_display_output($output, $GLOBALS['install_state'], $response->headers->all());
    exit;
  }

  $response->setContent($message);
  $response->setStatusCode(500, '500 Service unavailable (with message)');

  $response->send();
  // An exception must halt script execution.
  exit;
}

Whereas in D7, _drupal_log_error() passes through a themed maintenance page:

if ($fatal) {
  drupal_set_title(t('Error'));
  // We fallback to a maintenance page at this point, because the page generation
  // itself can generate errors.
  print theme('maintenance_page', array('content' => t('The website encountered an unexpected error. Please try again later.')));
  exit;
}
2
  • So has the option to supply your own offline template been removed in Drupal 8? If my database fails I'd rather my users see a maintenance page than a PDO error – nexus_6 Aug 1 '16 at 15:49
  • Correct, I added the D7 fatal error handling code for clarity. – Shawn Conn Aug 1 '16 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.