countdown-8.x-1.8/countdown.install

countdown.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the Countdown module.
 */

declare(strict_types=1);

use Drupal\Core\Url;

/**
 * Implements hook_requirements().
 */
function countdown_requirements($phase) {
  $requirements = [];

  if ($phase === 'runtime') {
    try {
      // Check if service exists before using it.
      if (!\Drupal::hasService('countdown.library_manager')) {
        $requirements['countdown_library'] = [
          'title' => t('Countdown Library'),
          'value' => t('Service unavailable'),
          'severity' => REQUIREMENT_WARNING,
          'description' => t('Countdown library manager service is not available. Try clearing caches.'),
        ];
        return $requirements;
      }

      /** @var \Drupal\countdown\Service\CountdownLibraryManagerInterface $library_manager */
      $library_manager = \Drupal::service('countdown.library_manager');

      // Get library requirements from the manager.
      $manager_requirements = $library_manager->getLibraryRequirements();

      // Map the manager's requirements to hook_requirements format.
      if (!empty($manager_requirements['countdown_library'])) {
        $req = $manager_requirements['countdown_library'];

        // Map severity values.
        $severity = REQUIREMENT_OK;
        if (isset($req['severity'])) {
          if ($req['severity'] === REQUIREMENT_ERROR) {
            $severity = REQUIREMENT_ERROR;
          }
          elseif ($req['severity'] === REQUIREMENT_WARNING) {
            $severity = REQUIREMENT_WARNING;
          }
        }

        $requirements['countdown_library'] = [
          'title' => $req['title'] ?? t('Countdown Library'),
          'value' => $req['value'] ?? t('Unknown'),
          'severity' => $severity,
          'description' => $req['description'] ?? '',
        ];
      }
      else {
        // Fallback if no requirements returned.
        $requirements['countdown_library'] = [
          'title' => t('Countdown Library'),
          'value' => t('Configured'),
          'severity' => REQUIREMENT_OK,
          'description' => t('Countdown library is configured and ready.'),
        ];
      }
    }
    catch (\Exception $e) {
      $requirements['countdown_library'] = [
        'title' => t('Countdown Library'),
        'value' => t('Error'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('Could not determine library status: @error', [
          '@error' => $e->getMessage(),
        ]),
      ];
    }
  }

  return $requirements;
}

/**
 * Implements hook_install().
 */
function countdown_install() {
  \Drupal::messenger()->addStatus(t('Visit the <a href=":url">settings page</a> to configure countdown libraries.', [
    ':url' => Url::fromRoute('countdown.settings')->toString(),
  ]));
}

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

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