You are here

public static function GeshiFilterCss::generateLanguagesCssFile in GeSHi Filter for syntax highlighting 8

Same name and namespace in other branches
  1. 8.2 src/GeshiFilterCss.php \Drupal\geshifilter\GeshiFilterCss::generateLanguagesCssFile()

Function for generating the external stylesheet.

Parameters

bool $force: Force the regeneration of the CSS file.

3 calls to GeshiFilterCss::generateLanguagesCssFile()
GeshiFilterLanguagesForm::submitForm in src/Form/GeshiFilterLanguagesForm.php
Form submission handler.
GeshiFilterSettingsForm::flushLanguageDefinitionCache in src/Form/GeshiFilterSettingsForm.php
Helper function for flushing the GeSHi language definition cache.
GeshiFilterSettingsForm::submitForm in src/Form/GeshiFilterSettingsForm.php
Form submission handler.

File

src/GeshiFilterCss.php, line 93

Class

GeshiFilterCss
Helper functions to work with css.

Namespace

Drupal\geshifilter

Code

public static function generateLanguagesCssFile($force = FALSE) {
  $languages = GeshiFilter::getEnabledLanguages();

  // Serialize the array of enabled languages as sort of hash.
  $languages_hash = serialize($languages);

  // Check if generation of the CSS file is needed.
  if ($force || $languages_hash != \Drupal::state()
    ->get('geshifilter_cssfile_languages')) {

    // Build stylesheet.
    $stylesheet = self::generateLanguagesCssRules();

    // Save stylesheet.
    $stylesheet_filename = self::languageCssPath();
    $ret = file_save_data($stylesheet, $stylesheet_filename, FILE_EXISTS_REPLACE);
    if ($ret) {
      drupal_set_message(t('(Re)generated external CSS style sheet %file.', [
        '%file' => $ret
          ->getFilename(),
      ]));
    }
    else {
      drupal_set_message(t('Could not generate external CSS file. Check the settings of your <a href="!filesystem">file system</a>.', [
        '!filesystem' => Url::fromRoute('system.file_system_settings')
          ->toString(),
      ]), 'error');
    }

    // Remember for which list of languages the CSS file was generated.
    \Drupal::state()
      ->set('cssfile_languages', $languages_hash);
  }
}