public static function CacheableMetadata::createFromObject in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Cache/CacheableMetadata.php \Drupal\Core\Cache\CacheableMetadata::createFromObject()
- 9 core/lib/Drupal/Core/Cache/CacheableMetadata.php \Drupal\Core\Cache\CacheableMetadata::createFromObject()
Creates a CacheableMetadata object from a depended object.
Parameters
\Drupal\Core\Cache\CacheableDependencyInterface|mixed $object: The object whose cacheability metadata to retrieve. If it implements CacheableDependencyInterface, its cacheability metadata will be used, otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.
Return value
static
27 calls to CacheableMetadata::createFromObject()
- BasicAuth::challengeException in core/
modules/ basic_auth/ src/ Authentication/ Provider/ BasicAuth.php - BlockRepository::getVisibleBlocksPerRegion in core/
modules/ block/ src/ BlockRepository.php - CacheableMetadataTest::testCreateFromObject in core/
tests/ Drupal/ Tests/ Core/ Cache/ CacheableMetadataTest.php - @covers ::createFromObject @dataProvider providerTestCreateFromObject
- CacheableNormalization::withCacheableDependency in core/
modules/ jsonapi/ src/ Normalizer/ Value/ CacheableNormalization.php - Gets a new CacheableNormalization with an additional dependency.
- CacheableResponseTrait::addCacheableDependency in core/
lib/ Drupal/ Core/ Cache/ CacheableResponseTrait.php
File
- core/
lib/ Drupal/ Core/ Cache/ CacheableMetadata.php, line 168
Class
- CacheableMetadata
- Defines a generic class for passing cacheability metadata.
Namespace
Drupal\Core\CacheCode
public static function createFromObject($object) {
if ($object instanceof CacheableDependencyInterface) {
$meta = new static();
$meta->cacheContexts = $object
->getCacheContexts();
$meta->cacheTags = $object
->getCacheTags();
$meta->cacheMaxAge = $object
->getCacheMaxAge();
return $meta;
}
// Objects that don't implement CacheableDependencyInterface must be assumed
// to be uncacheable, so set max-age 0.
$meta = new static();
$meta->cacheMaxAge = 0;
return $meta;
}