W3cubDocs

/Drupal 8

public static function CacheableMetadata::createFromRenderArray

public static CacheableMetadata::createFromRenderArray(array $build)

Creates a CacheableMetadata object with values taken from a render array.

Parameters

array $build: A render array.

Return value

static

File

core/lib/Drupal/Core/Cache/CacheableMetadata.php, line 149

Class

CacheableMetadata
Defines a generic class for passing cacheability metadata.

Namespace

Drupal\Core\Cache

Code

public static function createFromRenderArray(array $build) {
  $meta = new static();
  $meta->cacheContexts = (isset($build['#cache']['contexts'])) ? $build['#cache']['contexts'] : [];
  $meta->cacheTags = (isset($build['#cache']['tags'])) ? $build['#cache']['tags'] : [];
  $meta->cacheMaxAge = (isset($build['#cache']['max-age'])) ? $build['#cache']['max-age'] : Cache::PERMANENT;
  return $meta;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!CacheableMetadata.php/function/CacheableMetadata::createFromRenderArray/8.1.x