You are here

function rrssb_requirements in Ridiculously Responsive Social Sharing Buttons 8.2

Same name and namespace in other branches
  1. 7.2 rrssb.module \rrssb_requirements()
  2. 7 rrssb.module \rrssb_requirements()

Implements hook_requirements().

File

./rrssb.install, line 22
Contains install and update functions.

Code

function rrssb_requirements($phase) {

  // Check for library version.  We do a runtime check only,
  // as we don't want to block install - the normal sequence
  // is to install the module and then use the drush command to get the library.
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['rrssb']['title'] = t('RRSSB+ library');
    $library = \Drupal::service('library.discovery')
      ->getLibraryByName('rrssb', 'main');
    $downloadMessage = t('Please download the RRSSB library using "drush rrssb-plugin" or from <a href="@link">@link</a>.', [
      '@link' => RRSSB_LIBRARY_URI,
    ]);
    if (!isset($library['version'])) {
      $requirements['rrssb']['value'] = t('Not installed');
      $requirements['rrssb']['severity'] = REQUIREMENT_ERROR;
      $requirements['rrssb']['description'] = $downloadMessage;
    }
    else {
      $requirements['rrssb']['value'] = $library['version'];
      $compare = version_compare($library['version'], RRSSB_LIBRARY_MIN_VERSION);
      if ($compare < 0) {
        $requirements['rrssb']['severity'] = REQUIREMENT_ERROR;
        $requirements['rrssb']['description'] = t('Library version is too old.  @download', [
          '@download' => $downloadMessage,
        ]);
      }
      else {
        $requirements['rrssb']['severity'] = REQUIREMENT_OK;
      }
    }
  }
  return $requirements;
}