You are here

public function BlazyManagerBase::getCacheMetadata in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::getCacheMetadata()

Return the cache metadata common for all blazy-related modules.

1 call to BlazyManagerBase::getCacheMetadata()
BlazyManagerBase::setAttachments in src/BlazyManagerBase.php
Provides attachments and cache common for all blazy-related modules.

File

src/BlazyManagerBase.php, line 394

Class

BlazyManagerBase
Implements BlazyManagerInterface.

Namespace

Drupal\blazy

Code

public function getCacheMetadata(array $build = []) {
  $settings = isset($build['settings']) ? $build['settings'] : $build;
  $namespace = isset($settings['namespace']) ? $settings['namespace'] : 'blazy';
  $max_age = $this
    ->configLoad('cache.page.max_age', 'system.performance');
  $max_age = empty($settings['cache']) ? $max_age : $settings['cache'];
  $id = isset($settings['id']) ? $settings['id'] : Blazy::getHtmlId($namespace);
  $suffixes[] = empty($settings['count']) ? count(array_filter($settings)) : $settings['count'];
  $cache['tags'] = Cache::buildTags($namespace . ':' . $id, $suffixes, '.');
  $cache['contexts'] = [
    'languages',
  ];
  $cache['max-age'] = $max_age;
  $cache['keys'] = isset($settings['cache_metadata']['keys']) ? $settings['cache_metadata']['keys'] : [
    $id,
  ];
  if (!empty($settings['cache_tags'])) {
    $cache['tags'] = Cache::mergeTags($cache['tags'], $settings['cache_tags']);
  }
  return $cache;
}