You are here

private static function CacheMetadataExtractor::extractFromArray in Twig Tweak 3.1.x

Same name and namespace in other branches
  1. 3.x src/CacheMetadataExtractor.php \Drupal\twig_tweak\CacheMetadataExtractor::extractFromArray()

Extracts cache metadata from renders array.

1 call to CacheMetadataExtractor::extractFromArray()
CacheMetadataExtractor::extractCacheMetadata in src/CacheMetadataExtractor.php
Extracts cache metadata from object or render array.

File

src/CacheMetadataExtractor.php, line 43

Class

CacheMetadataExtractor
Cache metadata extractor service.

Namespace

Drupal\twig_tweak

Code

private static function extractFromArray(array $build) : CacheableMetadata {
  $cache_metadata = CacheableMetadata::createFromRenderArray($build);
  $keys = Element::children($build);
  foreach (array_intersect_key($build, array_flip($keys)) as $item) {
    $cache_metadata
      ->addCacheableDependency(self::extractFromArray($item));
  }
  return $cache_metadata;
}