class PathautoSettingsCacheTag in Pathauto 8
A subscriber to clear fielddefinition cache when saving pathauto settings.
Hierarchy
- class \Drupal\pathauto\EventSubscriber\PathautoSettingsCacheTag implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of PathautoSettingsCacheTag
1 string reference to 'PathautoSettingsCacheTag'
1 service uses PathautoSettingsCacheTag
File
- src/
EventSubscriber/ PathautoSettingsCacheTag.php, line 14
Namespace
Drupal\pathauto\EventSubscriberView source
class PathautoSettingsCacheTag implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The alias type manager.
*
* @var \Drupal\pathauto\AliasTypeManager
*/
protected $aliasTypeManager;
/**
* Constructs a PathautoSettingsCacheTag object.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\pathauto\AliasTypeManager $alias_type_manager
* The alias type manager.
*/
public function __construct(EntityFieldManagerInterface $entity_field_manager, AliasTypeManager $alias_type_manager) {
$this->entityFieldManager = $entity_field_manager;
$this->aliasTypeManager = $alias_type_manager;
}
/**
* Invalidate the 'rendered' cache tag whenever the settings are modified.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* The Event to process.
*/
public function onSave(ConfigCrudEvent $event) {
if ($event
->getConfig()
->getName() === 'pathauto.settings') {
$config = $event
->getConfig();
$original_entity_types = $config
->getOriginal('enabled_entity_types');
// Clear cached field definitions if the values are changed.
if ($original_entity_types != $config
->get('enabled_entity_types')) {
$this->entityFieldManager
->clearCachedFieldDefinitions();
$this->aliasTypeManager
->clearCachedDefinitions();
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = [
'onSave',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathautoSettingsCacheTag:: |
protected | property | The alias type manager. | |
PathautoSettingsCacheTag:: |
protected | property | ||
PathautoSettingsCacheTag:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
PathautoSettingsCacheTag:: |
public | function | Invalidate the 'rendered' cache tag whenever the settings are modified. | |
PathautoSettingsCacheTag:: |
public | function | Constructs a PathautoSettingsCacheTag object. |