hovercss-1.0.3/hovercss.install

hovercss.install
<?php

/**
 * @file
 * Install, update, uninstall Requirements functions for the HoverCSS module.
 */

define('HOVERCSS_DOWNLOAD_URL', 'https://github.com/IanLunn/Hover/archive/master.zip');

/**
 * Implements hook_requirements().
 */
function hovercss_requirements($phase) {
  if ($phase != 'runtime') {
    return [];
  }

  $requirements = [];

  // Check Hover.css library is exists.
  /** @var Drupal\Core\Asset\LibraryDiscovery $library_discovery */
  $library_discovery = \Drupal::service('library.discovery');
  $library_get_hover = $library_discovery->getLibraryByName('hovercss', 'hover.css');
  $library_exist_css = FALSE;

  // Check if $library_get_hover is an array before accessing its elements.
  if (is_array($library_get_hover) && isset($library_get_hover['css'][0]['data'])) {
    $library_exist_css = file_exists(DRUPAL_ROOT . '/' . $library_get_hover['css'][0]['data']);
  }

  // Check if the user has suppressed the library warning in HoverCSS UI.
  $suppressed_warning = \Drupal::configFactory()->get('hovercss.settings')->get('hide');

  // Show the status of the library in the status report section.
  if ($library_exist_css) {
    $description = t('The Hover.css library was available in the local libraries path and enabled.');
  }
  else {
    $description = t('The Hover.css library is using <strong>CDN</strong> and is not installed in your local libraries.<br>You can <a href="@downloadUrl" rel="external" target="_blank">download</a> and extract to "/libraries/hover" then check file exists in your Drupal installation directory at the correct path "/libraries/hover/css/hover-min.css".<br>See the HoverCSS module README file for more details.', [
      '@downloadUrl' => HOVERCSS_DOWNLOAD_URL,
    ]);
    // Returns TRUE for the library if the library
    // warning was hidden when using the CDN method.
    if ($suppressed_warning) {
      $library_exist_css = TRUE;
    }
  }

  $requirements['hovercss'] = [
    'title'       => t('Hover.css library'),
    'value'       => $library_exist_css ? t('Installed') : t('Not installed'),
    'severity'    => $library_exist_css ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    'description' => $description,
  ];

  return $requirements;
}

/**
 * Implements hook_install().
 */
function hovercss_install() {
  // Check for Hover.css library installation.
  $library_exists = hovercss_check_installed();
  if (!$library_exists) {
    \Drupal::messenger()->addWarning(t('The HoverCSS module requires the Hover.css library.<br>Currently, The Hover.css loaded via <strong>CDN</strong> and is not available in your local libraries.<br>Please <a href=":downloadUrl" rel="external" target="_blank">Download</a> and unzip into "/libraries/hover" directory.', [
      ':downloadUrl' => HOVERCSS_DOWNLOAD_URL,
    ]));
  }

  \Drupal::messenger()->addStatus(t('Thanks for installing HoverCSS module.'));
}

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

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