You are here

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'
pathauto.services.yml in ./pathauto.services.yml
pathauto.services.yml
1 service uses PathautoSettingsCacheTag
pathauto.settings_cache_tag in ./pathauto.services.yml
Drupal\pathauto\EventSubscriber\PathautoSettingsCacheTag

File

src/EventSubscriber/PathautoSettingsCacheTag.php, line 14

Namespace

Drupal\pathauto\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
PathautoSettingsCacheTag::$aliasTypeManager protected property The alias type manager.
PathautoSettingsCacheTag::$entityFieldManager protected property
PathautoSettingsCacheTag::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
PathautoSettingsCacheTag::onSave public function Invalidate the 'rendered' cache tag whenever the settings are modified.
PathautoSettingsCacheTag::__construct public function Constructs a PathautoSettingsCacheTag object.