You are here

trait HighContrastTrait in High contrast 8

This is an abstraction wrapper for controlling high contrast.

This class is provided to allow abstraction of the detection and setting of high contrast mode. Currently it is configured to use the session, but this allows for easier change if that may be required at some point.

Hierarchy

4 files declare their use of HighContrastTrait
HighContrastCacheContext.php in src/Cache/Context/HighContrastCacheContext.php
HighContrastStyleSheetTest.php in tests/src/FunctionalJavascript/HighContrastStyleSheetTest.php
HighContrastSwitchForm.php in src/Form/HighContrastSwitchForm.php
high_contrast.module in ./high_contrast.module
Allows users to switch to a high contrast version of the active theme.

File

src/HighContrastTrait.php, line 12

Namespace

Drupal\high_contrast
View source
trait HighContrastTrait {

  /**
   * Return if high contrast is enabled or not.
   *
   * @return bool
   *   TRUE if enabled, FALSE otherwise.
   */
  public static function highContrastEnabled() {
    return !empty($_SESSION['high_contrast']['enabled']) ? TRUE : FALSE;
  }

  /**
   * Enables high contrast mode.
   */
  public function enableHighContrast() {
    $_SESSION['high_contrast']['enabled'] = TRUE;
  }

  /**
   * Disables high contrast mode.
   */
  public function disableHighContrast() {
    $_SESSION['high_contrast']['enabled'] = FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HighContrastTrait::disableHighContrast public function Disables high contrast mode.
HighContrastTrait::enableHighContrast public function Enables high contrast mode.
HighContrastTrait::highContrastEnabled public static function Return if high contrast is enabled or not.