You are here

function fitvids_requirements in FitVids 8

Same name and namespace in other branches
  1. 6 fitvids.install \fitvids_requirements()
  2. 7 fitvids.install \fitvids_requirements()

If the plugin doesn't exist, show a warning on the status page

File

./fitvids.install, line 12
Install, update and uninstall functions for the Fitvids module.

Code

function fitvids_requirements($phase) {
  $requirements = [];

  // Check if plugin exists
  if ($phase == 'install') {
    $path = DRUPAL_ROOT . '/libraries/fitvids/jquery.fitvids.js';
    $installed = file_exists($path);
    if (!$installed) {

      // just a message will do here...
      // returning a $requirements array seems to crash drupal...
      \Drupal::messenger()
        ->addWarning(t('The FitVids.js jQuery plugin is missing. <a href="https://raw.github.com/davatron5000/FitVids.js/master/jquery.fitvids.js" rel="external">Download the plugin</a> and copy it to /libraries/fitvids/jquery.fitvids.js'));
    }
  }
  else {
    if ($phase == 'runtime') {
      $path = DRUPAL_ROOT . '/libraries/fitvids/jquery.fitvids.js';
      $installed = file_exists($path);
      if (!$installed) {
        $requirements['fitvids'] = [
          'title' => t('FitVids.js jQuery plugin'),
          'value' => t('Missing'),
          'description' => t('<a href=":url" rel="external">Download the plugin</a> and copy it to :library', [
            ':url' => FITVIDS_PLUGIN_URL,
            ':library' => FITVIDS_LIBRARY_PATH,
          ]),
          'severity' => REQUIREMENT_WARNING,
        ];
      }
      else {
        $requirements['fitvids'] = [
          'title' => t('FitVids.js jQuery plugin'),
          'value' => t('Installed'),
          'severity' => REQUIREMENT_OK,
        ];
      }
    }
  }
  return $requirements;
}