sitemap_status-1.0.0-alpha4/sitemap_status.module

sitemap_status.module
<?php

/**
 * @file
 * Contains sitemap_status.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\sitemap_status\SitemapStatusInterface;

/**
 * Implements hook_help().
 */
function sitemap_status_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the sitemap_status module.
    case 'help.page.sitemap_status':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Checks the locations statuses from a sitemap.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_toolbar().
 */
function sitemap_status_toolbar() {
  /** @var \Drupal\sitemap_status\SitemapStatusInterface $sitemapStatus */
  $sitemapStatus = \Drupal::service('sitemap_status');
  $statusIcon = $sitemapStatus->getStatusLevelIcon();
  $permission = \Drupal::currentUser()->hasPermission('access sitemap status');
  $trayLinks = [
    'configure_run' => [
      'title' => t('Check status'),
      'url' => Url::fromRoute('sitemap_status.settings'),
    ],
  ];
  $items['sitemap_status'] = [
    '#type' => 'toolbar_item',
    '#access' => $permission,
    '#attached' => [
      'library' => ['sitemap_status/sitemap_status'],
    ],
    // @todo caching invalidation.
    '#cache' => [
      'max-age' => 0,
    ],
    '#weight' => 150,
    'tab' => [
      '#type' => 'link',
      '#access' => $permission,
      '#title' => t('Sitemap status @status_icon', [
        '@status_icon' => $statusIcon,
      ]),
      '#url' => Url::fromRoute('system.status'),
      '#attributes' => [
        'title' => t('Check sitemap status'),
        'class' => [
          'toolbar-icon',
          'toolbar-item',
          'toolbar-icon-sitemap_status',
        ],
      ],
    ],
    'tray' => [
      '#theme' => 'links',
      '#links' => $trayLinks,
      '#attributes' => [
        'class' => ['toolbar-menu'],
      ],
    ],
  ];
  return $items;
}

/**
 * Implements hook_cron().
 */
function sitemap_status_cron() {
  $config = \Drupal::config('sitemap_status.settings');
  $frequency = $config->get('cron_frequency');
  if (!empty($frequency)) {
    $interval = 60 * 60 * 24 * $frequency;
    $lastCheck = \Drupal::state()->get(SitemapStatusInterface::STATE_LAST_CRON) ?: 0;
    $requestTime = \Drupal::time()->getRequestTime();
    if (($requestTime - $lastCheck) > $interval) {
      // Make sure to delete the state override from Drush.
      // To be removed once onQueueFinishedProcessing is implemented.
      // @see SitemapStatusCommand.
      \Drupal::state()->delete(SitemapStatusInterface::STATE_CONFIG_OVERRIDE);

      \Drupal::state()->set(SitemapStatusInterface::STATE_LAST_CRON, $requestTime);
      /** @var \Drupal\sitemap_status\SitemapStatusInterface $sitemapStatus */
      $sitemapStatus = \Drupal::service('sitemap_status');
      $sitemapStatus->checkLocations();
    }
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc