You are here

function simple_sitemap_requirements in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 simple_sitemap.install \simple_sitemap_requirements()
  2. 4.x simple_sitemap.install \simple_sitemap_requirements()

Implements hook_requirements().

Parameters

$phase:

Return value

array

File

./simple_sitemap.install, line 14
Module install and update procedures.

Code

function simple_sitemap_requirements($phase) {
  $requirements = [];
  if (!extension_loaded('xmlwriter')) {
    $requirements['simple_sitemap_php_extensions'] = [
      'title' => t('Simple XML sitemap PHP extensions'),
      'value' => t('Missing PHP xmlwriter extension'),
      'description' => t('In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled.'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  switch ($phase) {
    case 'runtime':
      $generator = \Drupal::service('simple_sitemap.generator');
      $generated_ago = $generator
        ->getGeneratedAgo();
      $cron_generation = $generator
        ->getSetting('cron_generate');
      if (!$generated_ago) {
        $value = t('Not available');
        $description = t($cron_generation ? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.' : 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [
          '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap',
        ]);
        $severity = REQUIREMENT_WARNING;
      }
      else {
        $value = t('XML sitemap is available');
        $description = t('The <a href="@sitemap">XML sitemap</a> was generated @ago ago.' . ' ' . ($cron_generation ? 'Run cron, or <a href="@generate">regenerate</a> the sitemap manually.' : 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemap manually.'), [
          '@sitemap' => $GLOBALS['base_url'] . '/sitemap.xml',
          '@ago' => $generated_ago,
          '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap',
        ]);
        $severity = REQUIREMENT_INFO;
      }
      $requirements['simple_sitemap_generated'] = [
        'title' => 'Simple XML sitemap',
        'value' => $value,
        'description' => $description,
        'severity' => $severity,
      ];
      break;
  }
  return $requirements;
}