function MediaConfigSubscriber::onSave

Same name in other branches
  1. 9 core/modules/media/src/EventSubscriber/MediaConfigSubscriber.php \Drupal\media\EventSubscriber\MediaConfigSubscriber::onSave()
  2. 10 core/modules/media/src/EventSubscriber/MediaConfigSubscriber.php \Drupal\media\EventSubscriber\MediaConfigSubscriber::onSave()
  3. 11.x core/modules/media/src/EventSubscriber/MediaConfigSubscriber.php \Drupal\media\EventSubscriber\MediaConfigSubscriber::onSave()

Updates entity type definitions and ensures routes are rebuilt when needed.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event: The ConfigCrudEvent to process.

File

core/modules/media/src/EventSubscriber/MediaConfigSubscriber.php, line 60

Class

MediaConfigSubscriber
Listens to the config save event for media.settings.

Namespace

Drupal\media\EventSubscriber

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.