Disable "Operating in maintenance mode. Go online." 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(&amp;$vars) {
  if (variable_get('maintenance_mode', 0)) {
    $message_count = count($_SESSION['messages']['status']);
    if($message_count &gt; 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.
Drupal 8 version:

function mytheme_preprocess_status_messages(&amp;$variables) {
  if (\Drupal::state()-&gt;get('system.maintenance_mode')) {
    $message_count = count($variables['message_list']['status']);
    if ($message_count &gt; 1) {
      array_shift($variables['message_list']['status']);
    }
    else {
      unset($variables['message_list']['status']);
    }
  }
}