Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / EventSubscriber / PathautoSettingsCacheTag.php
1 <?php
2
3 namespace Drupal\pathauto\EventSubscriber;
4
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;
10
11 /**
12  * A subscriber to clear fielddefinition cache when saving pathauto settings.
13  */
14 class PathautoSettingsCacheTag implements EventSubscriberInterface {
15
16   /**
17    * @var \Drupal\Core\Entity\EntityFieldManagerInterface
18    */
19   protected $entityFieldManager;
20
21   /**
22    * The alias type manager.
23    *
24    * @var \Drupal\pathauto\AliasTypeManager
25    */
26   protected $aliasTypeManager;
27
28   /**
29    * Constructs a PathautoSettingsCacheTag object.
30    *
31    * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
32    *   The entity field manager.
33    * @param \Drupal\pathauto\AliasTypeManager $alias_type_manager
34    *   The alias type manager.
35    */
36   public function __construct(EntityFieldManagerInterface $entity_field_manager, AliasTypeManager $alias_type_manager) {
37     $this->entityFieldManager = $entity_field_manager;
38     $this->aliasTypeManager = $alias_type_manager;
39   }
40
41   /**
42    * Invalidate the 'rendered' cache tag whenever the settings are modified.
43    *
44    * @param \Drupal\Core\Config\ConfigCrudEvent $event
45    *   The Event to process.
46    */
47   public function onSave(ConfigCrudEvent $event) {
48     if ($event->getConfig()->getName() === 'pathauto.settings') {
49       $config = $event->getConfig();
50       $original_entity_types = $config->getOriginal('enabled_entity_types');
51
52       // Clear cached field definitions if the values are changed.
53       if ($original_entity_types != $config->get('enabled_entity_types')) {
54         $this->entityFieldManager->clearCachedFieldDefinitions();
55         $this->aliasTypeManager->clearCachedDefinitions();
56       }
57     }
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public static function getSubscribedEvents() {
64     $events[ConfigEvents::SAVE][] = ['onSave'];
65     return $events;
66   }
67
68 }