You are here

function pwa_requirements in Progressive Web App 7

Same name and namespace in other branches
  1. 8 pwa.install \pwa_requirements()
  2. 7.2 pwa.install \pwa_requirements()
  3. 2.x pwa.install \pwa_requirements()

Implements hook_requirements().

File

./pwa.install, line 9

Code

function pwa_requirements($phase) {
  $requirements = [];
  if ($phase !== 'runtime') {
    return $requirements;
  }
  $t = get_t();
  if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' || isset($_SERVER["REQUEST_SCHEME"]) && $_SERVER["REQUEST_SCHEME"] === 'https') {
    $requirements['pwa'] = array(
      'title' => $t('Progressive Web App'),
      'value' => $t('HTTPS on'),
      'severity' => REQUIREMENT_OK,
      'description' => $t('Please make sure the certificate of %domain is valid for offline functionality to work.', [
        '%domain' => $_SERVER['HTTP_HOST'],
      ]),
    );
  }
  elseif (in_array($_SERVER['HTTP_HOST'], [
    'localhost',
    '127.0.0.1',
  ])) {
    $requirements['pwa'] = array(
      'title' => $t('Progressive Web App'),
      'value' => 'localhost',
      'severity' => REQUIREMENT_WARNING,
      'description' => $t('You will need to configure HTTPS on your production site for the Progressive Web App to function.'),
    );
  }
  else {
    $requirements['pwa'] = array(
      'title' => $t('Progressive Web App'),
      'value' => $t('HTTPS off'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $t('HTTPS needs to be configured to enable your Progressive Web App. Without a secure connection, the Service Worker will not install itself.'),
    );
  }
  return $requirements;
}