Chris@18: routeBuilder = $router_builder; Chris@18: $this->cacheTagsInvalidator = $cache_tags_invalidator; Chris@18: $this->entityTypeManager = $entity_type_manager; Chris@18: } Chris@18: Chris@18: /** Chris@18: * Updates entity type definitions and ensures routes are rebuilt when needed. Chris@18: * Chris@18: * @param \Drupal\Core\Config\ConfigCrudEvent $event Chris@18: * The ConfigCrudEvent to process. Chris@18: */ Chris@18: public function onSave(ConfigCrudEvent $event) { Chris@18: $saved_config = $event->getConfig(); Chris@18: if ($saved_config->getName() === 'media.settings' && $event->isChanged('standalone_url')) { Chris@18: $this->cacheTagsInvalidator->invalidateTags([ Chris@18: // The configuration change triggers entity type definition changes, Chris@18: // which in turn triggers routes to appear or disappear. Chris@18: // @see media_entity_type_alter() Chris@18: 'entity_types', Chris@18: // The 'rendered' cache tag needs to be explicitly invalidated to ensure Chris@18: // that all links to Media entities are re-rendered. Ideally, this would Chris@18: // not be necessary; invalidating the 'entity_types' cache tag should be Chris@18: // sufficient. But that cache tag would then need to be on nearly Chris@18: // everything, resulting in excessive complexity. We prefer pragmatism. Chris@18: 'rendered', Chris@18: ]); Chris@18: // @todo Remove this when invalidating the 'entity_types' cache tag is Chris@18: // respected by the entity type plugin manager. See Chris@18: // https://www.drupal.org/project/drupal/issues/3001284 and Chris@18: // https://www.drupal.org/project/drupal/issues/3013659. Chris@18: $this->entityTypeManager->clearCachedDefinitions(); Chris@18: $this->routeBuilder->setRebuildNeeded(); Chris@18: } Chris@18: } Chris@18: Chris@18: /** Chris@18: * {@inheritdoc} Chris@18: */ Chris@18: public static function getSubscribedEvents() { Chris@18: $events[ConfigEvents::SAVE][] = ['onSave']; Chris@18: return $events; Chris@18: } Chris@18: Chris@18: }