You are here

function xmlsitemap_check_status in XML sitemap 8

Same name and namespace in other branches
  1. 6.2 xmlsitemap.inc \xmlsitemap_check_status()
  2. 7.2 xmlsitemap.inc \xmlsitemap_check_status()
  3. 2.x xmlsitemap.module \xmlsitemap_check_status()

Check the status of all hook_requirements() from any xmlsitemap modules.

Return value

bool TRUE if all requirements are met, FALSE otherwise.

1 call to xmlsitemap_check_status()
XmlSitemapListBuilder::render in src/XmlSitemapListBuilder.php
Builds the entity listing as renderable array for table.html.twig.

File

./xmlsitemap.module, line 2378
xmlsitemap XML sitemap

Code

function xmlsitemap_check_status() {
  $messages =& drupal_static(__FUNCTION__);
  if (!isset($messages)) {

    // Cache the list of modules that are checked.
    if ($cache = \Drupal::cache()
      ->get('xmlsitemap:registry:requirements')) {
      $modules = $cache->data;
    }
    else {
      $modules = [];
      \Drupal::moduleHandler()
        ->loadAllIncludes('install');
      foreach (\Drupal::moduleHandler()
        ->getImplementations('requirements') as $module) {
        if (strpos($module, 'xmlsitemap') !== FALSE) {
          $modules[] = $module;
        }
      }
      \Drupal::cache()
        ->set('xmlsitemap:registry:requirements', $modules, Cache::PERMANENT, [
        'xmlsitemap',
      ]);
    }
    $messages = [];
    foreach ($modules as $module) {
      module_load_install($module);
      $requirements = \Drupal::moduleHandler()
        ->invoke($module, 'requirements', [
        'runtime',
      ]);
      foreach ($requirements as $requirement) {
        if (isset($requirement['severity']) && max(REQUIREMENT_OK, $requirement['severity'])) {
          $messages[] = $requirement['description'];
        }
      }
    }
    if ($messages) {
      $messages = [
        '#type' => 'item_list',
        '#items' => [
          $messages,
        ],
      ];
      $message = t('One or more problems were detected with your XML sitemap configuration: @messages', [
        '@messages' => \Drupal::service('renderer')
          ->render($messages),
      ]);
      \Drupal::messenger()
        ->addWarning($message, FALSE);
      if (\Drupal::currentUser()
        ->hasPermission('access site reports')) {
        \Drupal::messenger()
          ->addWarning(t('Check the <a href="@status-report">status report</a> for more information.', [
          '@status-report' => Url::fromRoute('system.status')
            ->toString(),
        ]), FALSE);
      }
    }
  }
  return !empty($messages);
}