You are here

function geshifilter_requirements in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 geshifilter.install \geshifilter_requirements()
  2. 5.2 geshifilter.module \geshifilter_requirements()
  3. 6 geshifilter.module \geshifilter_requirements()
  4. 7 geshifilter.module \geshifilter_requirements()

Implements hook_requirements().

File

./geshifilter.install, line 33
Installation and uninstallation functions for the GeSHi filter.

Code

function geshifilter_requirements($phase) {
  $config = \Drupal::config('geshifilter.settings');
  $requirements = [];
  if ($phase == 'runtime') {

    // Check if GeSHi library is available.
    $geshi_library = GeshiFilter::loadGeshi();
    if (!$geshi_library['loaded']) {
      $requirements['geshifilter_library'] = [
        'title' => 'GeSHi filter',
        'value' => t('GeSHi library not found'),
        'description' => t('GeSHi library not found. Read the <em>INSTALLATION</em> section of <a href=":readme_url">README.txt</a> for information on how to fix this error.', [
          ':readme_url' => Url::fromUri('http://cgit.drupalcode.org/geshifilter/tree/README.txt', [
            'query' => [
              'h' => '8.x-1.x',
            ],
          ])
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
    elseif (($version = explode('.', GESHI_VERSION)) && !($version[0] == '1' && $version[1] == '0')) {
      $requirements['geshifilter_library'] = [
        'title' => 'GeSHi filter',
        'value' => t('GeSHi library invalid version.'),
        'description' => t('The detected version of GeSHi library (%version) is not supported. A version from the 1.0.x branch is required. Read the <em>INSTALLATION</em> section of <a href=":readme_url">README.txt</a> for information on how to fix this error.', [
          '%version' => GESHI_VERSION,
          ':readme_url' => Url::fromUri('http://cgit.drupalcode.org/geshifilter/tree/README.txt', [
            'query' => [
              'h' => '8.x-1.x',
            ],
          ])
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
    else {
      $requirements['geshifilter_library'] = [
        'title' => 'GeSHi filter',
        // GESHI_VERSION is defined in GeSHi library.
        'value' => t('Found GeSHi library version %version', [
          '%version' => GESHI_VERSION,
        ]),
        'severity' => REQUIREMENT_OK,
        'description' => t('The detected version of GeSHi library is supported.'),
      ];
    }

    // Warn if GeSHi filter is configured to automatically managed external
    // stylesheet when it's not possible.
    if ($config
      ->get('css_mode') == Geshifilter::CSS_CLASSES_AUTOMATIC && !GeshifilterCss::managedExternalStylesheetPossible()) {
      $requirements['geshifilter_css_mode'] = [
        'title' => 'GeSHi filter CSS mode',
        'value' => t('GeSHi filter can not automatically manage an external style sheet when the download method is private. Read the <em>INSTALLATION</em> section of <a href=":readme_url">README.txt</a> for information on how to fix this error.', [
          ':readme_url' => Url::fromUri('http://cgit.drupalcode.org/geshifilter/tree/README.txt', [
            'query' => [
              'h' => '8.x-1.x',
            ],
          ])
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('Change the CSS mode of the <a href=":geshi">GeSHi filter</a> or change the <a href=":filesystem">download mode</a> to public.', [
          ':geshi' => URL::fromRoute('geshifilter.settings')
            ->toString(),
          ':filesystem' => URL::fromRoute('system.file_system_settings')
            ->toString(),
        ]),
      ];
    }

    // // Check for filter conflicts.
    // if (count(GeshiFilterConflicts::listConflicts()) > 0) {
    // $requirements[] = array(
    // 'title' => 'GeSHi filter',
    // 'value' => t('Some filter conflicts were detected.'),
    // 'description' => \Drupal::l('View and resolve the detected
    // filter conflicts',
    // URL::fromRoute('geshifilter.settings_filter_conflicts')),
    // 'severity' => REQUIREMENT_ERROR,
    // );
    // }.
  }
  return $requirements;
}