Question

The solution for Drupal 7 is using the following code, as per answer of How can I disable the message “Operating in maintenance mode. Go online.” in maintenance mode?

function mytheme_preprocess_page(&$vars) {
  if (variable_get('maintenance_mode', 0)) {
    $message_count = count($_SESSION['messages']['status']);
    if($message_count > 1) {
      array_shift($_SESSION['messages']['status']);
    }
    else {
      unset($_SESSION['messages']['status']);
    }
  }
}

What is the solution for Drupal 8?

I cannot figure out how to do it with https://www.drupal.org/project/disable_messages.

Hide/disable the message for everyone including the user #1.

Was it helpful?

Solution

Drupal 8 version:

function mytheme_preprocess_status_messages(&$variables) {
  if (\Drupal::state()->get('system.maintenance_mode')) {
    $message_count = count($variables['message_list']['status']);
    if ($message_count > 1) {
      array_shift($variables['message_list']['status']);
    }
    else {
      unset($variables['message_list']['status']);
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top