You are here

high_contrast.install in High contrast 8

Same filename and directory in other branches
  1. 6 high_contrast.install
  2. 7 high_contrast.install

Contains install and update functions for High Contrast.

File

high_contrast.install
View source
<?php

use Drupal\file\Entity\File;

/**
 * @file
 * Contains install and update functions for High Contrast.
 */

/**
 * Implements hook_uninstall().
 */
function high_contrast_uninstall() {
  $path = HIGH_CONTRAST_CSS_LOCATION;
  if (file_exists($path)) {
    \Drupal::service('file_system')
      ->delete($path);
  }
}

/**
 * Regenerate the CSS file in its new location.
 */
function high_contrast_update_8001() {

  // Updating the CSS file is triggered by a configuration save.
  \Drupal::configFactory()
    ->getEditable('high_contrast.settings')
    ->save();
}

/**
 * Delete the old CSS file.
 */
function high_contrast_update_8002() {
  $path = 'public://high_contrast.css';
  if (file_exists($path)) {
    \Drupal::service('file_system')
      ->delete($path);
  }
}

/**
 * Remove database entry for the high_contrast.css file.
 */
function high_contrast_update_8003() {
  $database = \Drupal::database();
  $query = $database
    ->query('SELECT fid FROM {file_managed} where uri=:uri', [
    ':uri' => HIGH_CONTRAST_CSS_LOCATION,
  ]);
  $result = $query
    ->fetchAll();
  foreach ($result as $record) {
    $file = File::load($record->fid);
    $file
      ->delete();
  }

  // Re-add the CSS file by saving configuration.
  \Drupal::configFactory()
    ->getEditable('high_contrast.settings')
    ->save();
}

Functions

Namesort descending Description
high_contrast_uninstall Implements hook_uninstall().
high_contrast_update_8001 Regenerate the CSS file in its new location.
high_contrast_update_8002 Delete the old CSS file.
high_contrast_update_8003 Remove database entry for the high_contrast.css file.