class ExtlinkSettingsSaveEventSubscriber in External Links 8
Clears JS and asset libraries in response to changes in extlink settings.
Hierarchy
- class \Drupal\extlink\EventSubscriber\ExtlinkSettingsSaveEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ExtlinkSettingsSaveEventSubscriber
1 string reference to 'ExtlinkSettingsSaveEventSubscriber'
1 service uses ExtlinkSettingsSaveEventSubscriber
File
- src/
EventSubscriber/ ExtlinkSettingsSaveEventSubscriber.php, line 14
Namespace
Drupal\extlink\EventSubscriberView source
class ExtlinkSettingsSaveEventSubscriber implements EventSubscriberInterface {
/**
* The CSS/JS asset library discovery service.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryInterface
*/
protected $libraryDiscovery;
/**
* The JS asset optimizer service.
*
* @var \Drupal\Core\Asset\AssetCollectionOptimizerInterface
*/
protected $jsOptimizer;
/**
* ExtlinkSettingsSaveEventSubscriber constructor.
*
* @param \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery
* The CSS/JS asset library discovery service.
* @param \Drupal\Core\Asset\AssetCollectionOptimizerInterface $js_optimizer
* The JS asset optimizer service.
*/
public function __construct(LibraryDiscoveryInterface $library_discovery, AssetCollectionOptimizerInterface $js_optimizer) {
$this->libraryDiscovery = $library_discovery;
$this->jsOptimizer = $js_optimizer;
}
/**
* Acts on changes to extlink.settings to flush JS library and assets.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The configuration event.
*/
public function onConfigSave(ConfigCrudEvent $event) {
$config = $event
->getConfig();
if ($config
->getName() === 'extlink.settings') {
$flush_js_files = $config
->get('extlink_use_external_js_file');
if ($event
->isChanged('extlink_use_external_js_file')) {
// When using external JS file is enabled or disabled, need to flush the
// library discovery cache to update the dependencies of drupal.extlink
// library.
$this->libraryDiscovery
->clearCachedDefinitions();
$flush_js_files = TRUE;
}
if ($flush_js_files) {
// Flush the optimized JS files if using an external JS file when the
// settings are saved. Also flush the optimized JS files when disabling
// or enabling using the external JS files.
$this->jsOptimizer
->deleteAll();
_drupal_flush_css_js();
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
ConfigEvents::SAVE => 'onConfigSave',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtlinkSettingsSaveEventSubscriber:: |
protected | property | The JS asset optimizer service. | |
ExtlinkSettingsSaveEventSubscriber:: |
protected | property | The CSS/JS asset library discovery service. | |
ExtlinkSettingsSaveEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ExtlinkSettingsSaveEventSubscriber:: |
public | function | Acts on changes to extlink.settings to flush JS library and assets. | |
ExtlinkSettingsSaveEventSubscriber:: |
public | function | ExtlinkSettingsSaveEventSubscriber constructor. |