class ConfigEventSubscriber in High contrast 8
A subscriber for updating the stylesheet when the configuration is updated.
Hierarchy
- class \Drupal\high_contrast\EventSubscriber\ConfigEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigEventSubscriber
1 string reference to 'ConfigEventSubscriber'
1 service uses ConfigEventSubscriber
File
- src/
EventSubscriber/ ConfigEventSubscriber.php, line 14
Namespace
Drupal\high_contrast\EventSubscriberView source
class ConfigEventSubscriber implements EventSubscriberInterface {
/**
* The file system.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Config factory interface.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
private $configFactory;
/**
* Constructs a ConfigEventSubscriber object.
*
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(FileSystemInterface $file_system, ConfigFactoryInterface $config_factory) {
$this->fileSystem = $file_system;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = [
'updateStylesheet',
];
return $events;
}
/**
* Regenerate the stylesheet.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The Event to process.
*/
public function updateStylesheet(ConfigCrudEvent $event) {
// Check if the save came from the high contrast configuration.
if ($event
->getConfig()
->getName() === 'high_contrast.settings') {
$dir = HIGH_CONTRAST_CSS_FOLDER;
$file = HIGH_CONTRAST_CSS_LOCATION;
$this->fileSystem
->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY);
$config = $this->configFactory
->get('high_contrast.settings');
$css = _high_contrast_build_css($config
->get('colors_background'), $config
->get('colors_text'), $config
->get('colors_hyperlinks'));
$this->fileSystem
->saveData($css, $file, FileSystemInterface::EXISTS_REPLACE);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEventSubscriber:: |
private | property | Config factory interface. | |
ConfigEventSubscriber:: |
protected | property | The file system. | |
ConfigEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigEventSubscriber:: |
public | function | Regenerate the stylesheet. | |
ConfigEventSubscriber:: |
public | function | Constructs a ConfigEventSubscriber object. |