You are here

public function SocialTaggingOverrides::getCacheableMetadata in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  2. 8 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  3. 8.2 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  4. 8.3 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  5. 8.4 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  6. 8.5 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  7. 8.6 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  8. 8.8 modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  9. 10.3.x modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  10. 10.0.x modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  11. 10.1.x modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()
  12. 10.2.x modules/social_features/social_tagging/src/SocialTaggingOverrides.php \Drupal\social_tagging\SocialTaggingOverrides::getCacheableMetadata()

Gets the cacheability metadata associated with the config factory override.

Parameters

string $name: The name of the configuration override to get metadata for.

Return value

\Drupal\Core\Cache\CacheableMetadata A cacheable metadata object.

Overrides ConfigFactoryOverrideInterface::getCacheableMetadata

File

modules/social_features/social_tagging/src/SocialTaggingOverrides.php, line 318

Class

SocialTaggingOverrides
Configuration override.

Namespace

Drupal\social_tagging

Code

public function getCacheableMetadata($name) {

  // If this override doesn't apply to the given config then we return an
  // empty cacheable metadata object that can be cached forever.
  if (!$this
    ->shouldApplyOverrides([
    $name,
  ])) {
    return new CacheableMetadata();
  }

  // We could dinstinguish between the various configurations that we override
  // in how granular we cache. However, for simplicty just cache based on all
  // the calls that are made in the loadOverrides method and assume this is
  // the same for any config that's overridden.
  $metadata = new CacheableMetadata();

  // Calls to SocialTaggingService's methods active, groupActive, allowSplit
  // all depend on the settings under the hood.
  $metadata
    ->addCacheContexts([
    'config:social_tagging.settings',
  ]);

  // The loadOverrides method calls the getCategories and getChildren methods
  // to build the fields that are shown in the views and the values they have.
  // The output of these methods ultimately depends on the contents of the
  // `social_tagging` vocabulary. With that in mind we want to invalidate on
  // any taxonomy change in the `social_tagging` vocabulary which we can do
  // with the `taxonomy_term_list` cache tag that's automatically defined as
  // EntityType::id . '_list_' in EntityType::__construct. Additionally as of
  // 8.9.0 (https://www.drupal.org/node/3107058) we can specify a specific
  // Taxonomy bundle. (Remember that a taxonomy Term bundle is its
  // vocabulary).
  // So for Drupal versions before 8.9.0 we'll have to invalidate on any term
  // addition and for anything above 8.9.0 we can enjoy a performance
  // increase.
  if (version_compare(\Drupal::VERSION, '8.9', '<')) {
    $metadata
      ->addCacheTags([
      'taxonomy_term_list',
    ]);
  }
  else {
    $metadata
      ->addCacheTags([
      'taxonomy_term_list:social_tagging',
    ]);
  }

  // The above should ensure that if things change in the tagging
  // configuration or the available tags, the search UI is rebuilt.
  return $metadata;
}