You are here

function acsf_form_system_site_maintenance_mode_alter in Acquia Cloud Site Factory Connector 8

Same name and namespace in other branches
  1. 8.2 acsf.module \acsf_form_system_site_maintenance_mode_alter()

Implements hook_form_FORM_ID_alter().

File

./acsf.module, line 86
Acquia Cloud Site Factory Connector.

Code

function acsf_form_system_site_maintenance_mode_alter(&$form, FormStateInterface $form_state, $form_id) {
  $messenger = \Drupal::messenger();
  $acsf_maintenance_time = \Drupal::config('acsf.settings')
    ->get('maintenance_time');
  $maintenance_mode = \Drupal::state()
    ->get('system.maintenance_mode');
  if ($acsf_maintenance_time && $maintenance_mode) {
    $messenger
      ->addMessage(t('ACSF site maintenance in progress.'), 'warning');
    if (\Drupal::time()
      ->getRequestTime() > $acsf_maintenance_time) {

      // The update is taking longer than expected.
      $messenger
        ->addMessage(t('The maintenance was expected to be done already - please be patient. Reload this page to see if maintenance is complete.'), 'warning');
    }
    else {

      // Never show an interval less than 1 minute.
      $remaining = \Drupal::service('date.formatter')
        ->formatInterval(60 + $acsf_maintenance_time - \Drupal::time()
        ->getRequestTime(), 1);
      $messenger
        ->addMessage(t('The maintenance should be completed within :interval. Reload this page to see if maintenance is complete.', [
        ':interval' => $remaining,
      ]), 'warning');
    }
    $form['maintenance_mode']['#attributes']['disabled'][] = 'disabled';
  }
}