You are here

function advagg_requirements in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.2 advagg.install \advagg_requirements()
  2. 8.3 advagg.install \advagg_requirements()
  3. 6 advagg.install \advagg_requirements()
  4. 7.2 advagg.install \advagg_requirements()
  5. 7 advagg.install \advagg_requirements()

Implements hook_requirements().

File

./advagg.install, line 58
Handles Advanced Aggregation installation and upgrade tasks.

Code

function advagg_requirements($phase) {
  $requirements = [];

  // Ensure translations don't break at install time.
  $t = 't';

  // Always check these, independent of the current phase.
  $function_list = [
    'rename',
  ];

  // Check each function to make sure it exists.
  foreach ($function_list as $function_name) {
    if (!function_exists($function_name)) {
      $requirements['advagg_function_' . $function_name] = [
        'title' => $t('Adv CSS/JS Agg - Function Disabled'),
        'value' => $phase === 'install' ? FALSE : $function_name,
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('<a href="!url">%name()</a> is disabled on this server. Please contact your hosting provider or server administrator and see if they can re-enable this function for you.', [
          '!url' => 'http://php.net/' . str_replace('_', '-', $function_name),
          '%name' => $function_name,
        ]),
      ];
    }
  }

  // If not at runtime, return here.
  if ($phase !== 'runtime') {
    return $requirements;
  }
  $config = \Drupal::config('advagg.settings');
  if (!$config
    ->get('skip_enabled_preprocess_check')) {

    // Make sure variables are set correctly.
    if (!$config
      ->get('enabled')) {
      $requirements['advagg_not_on'] = [
        'title' => $t('Adv CSS/JS Agg - Enabled'),
        'severity' => REQUIREMENT_WARNING,
        'value' => $t('Advanced CSS/JS aggregation is disabled.'),
        'description' => $t('Go to the Advanced CSS/JS aggregation <a href="@settings">settings page</a> and enable it.', [
          '@settings' => Url::fromRoute('advagg.settings')
            ->toString(),
        ]),
      ];
    }
  }
  $advaggMessages = [];
  if (!$config
    ->get('enabled')) {
    $advaggMessages[] = $t('Advanced CSS/JS aggregation is disabled. Go to the Advanced CSS/JS aggregation <a href="@settings">settings page</a> and enable it.', [
      '@settings' => Url::fromRoute('advagg.settings')
        ->toString(),
    ]);
  }
  if ($config
    ->get('cache_level') === 0) {
    $advaggMessages[] = $t('Currently running in development mode.');
  }
  $requirements['advagg_ok'] = [
    'title' => $t('Adv CSS/JS Agg'),
    'severity' => REQUIREMENT_OK,
    'value' => $t('Advanced CSS/JS Aggregator should be working correctly.'),
    'description' => [
      '#theme' => 'item_list',
      '#items' => $advaggMessages,
      '#title' => '',
      '#list_type' => 'ul',
      '#attributes' => [],
    ],
  ];
  return $requirements;
}