3 namespace Drupal\pathauto\EventSubscriber;
5 use Drupal\Core\Config\ConfigCrudEvent;
6 use Drupal\Core\Config\ConfigEvents;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8 use Drupal\Core\Entity\EntityFieldManagerInterface;
9 use Drupal\pathauto\AliasTypeManager;
12 * A subscriber to clear fielddefinition cache when saving pathauto settings.
14 class PathautoSettingsCacheTag implements EventSubscriberInterface {
16 protected $entityFieldManager;
17 protected $aliasTypeManager;
20 * Constructs a PathautoSettingsCacheTag object.
22 public function __construct(EntityFieldManagerInterface $entity_field_manager, AliasTypeManager $alias_type_manager) {
23 $this->entityFieldManager = $entity_field_manager;
24 $this->aliasTypeManager = $alias_type_manager;
28 * Invalidate the 'rendered' cache tag whenever the settings are modified.
30 * @param \Drupal\Core\Config\ConfigCrudEvent $event
31 * The Event to process.
33 public function onSave(ConfigCrudEvent $event) {
34 if ($event->getConfig()->getName() === 'pathauto.settings') {
35 $config = $event->getConfig();
36 $original_entity_types = $config->getOriginal('enabled_entity_types');
38 // Clear cached field definitions if the values are changed.
39 if ($original_entity_types != $config->get('enabled_entity_types')) {
40 $this->entityFieldManager->clearCachedFieldDefinitions();
41 $this->aliasTypeManager->clearCachedDefinitions();
49 public static function getSubscribedEvents() {
50 $events[ConfigEvents::SAVE][] = ['onSave'];