class WebformBubbleableMetadata in Webform 8.5
Same name and namespace in other branches
- 6.x src/Cache/WebformBubbleableMetadata.php \Drupal\webform\Cache\WebformBubbleableMetadata
Value object used for bubbleable rendering metadata for webforms.
Hierarchy
- class \Drupal\Core\Cache\CacheableMetadata implements RefinableCacheableDependencyInterface uses RefinableCacheableDependencyTrait
- class \Drupal\Core\Render\BubbleableMetadata implements AttachmentsInterface uses AttachmentsTrait
- class \Drupal\webform\Cache\WebformBubbleableMetadata
- class \Drupal\Core\Render\BubbleableMetadata implements AttachmentsInterface uses AttachmentsTrait
Expanded class hierarchy of WebformBubbleableMetadata
3 files declare their use of WebformBubbleableMetadata
- WebformBubbleableMetadataTest.php in tests/
src/ Unit/ Cache/ WebformBubbleableMetadataTest.php - WebformElementBase.php in src/
Plugin/ WebformElementBase.php - WebformSubmissionForm.php in src/
WebformSubmissionForm.php
File
- src/
Cache/ WebformBubbleableMetadata.php, line 11
Namespace
Drupal\webform\CacheView source
class WebformBubbleableMetadata extends BubbleableMetadata {
/**
* Appends the values of this bubbleable metadata object to a render array.
*
* We can't use \Drupal\Core\Render\BubbleableMetadata::applyTo because it
* replaces all existing cache contexts and tags.
*
* @param array $build
* A render array
*
* @see \Drupal\Core\Render\BubbleableMetadata::applyTo
* @see \Drupal\webform\WebformSubmissionForm::buildForm
* @see \Drupal\webform\Plugin\WebformElementBase::replaceTokens
*/
public function appendTo(array &$build) {
$contexts = $this
->getCacheContexts();
$tags = $this
->getCacheTags();
$max_age = $this
->getCacheMaxAge();
$attachments = $this
->getAttachments();
// Make sure cache metadata has been set.
if (empty($contexts) && empty($tags) && empty($attachments) && $max_age === Cache::PERMANENT) {
return;
}
// The below code is copied from Renderer::mergeBubbleableMetadata.
// @see \Drupal\Core\Render\Renderer::mergeBubbleableMetadata
$meta_a = BubbleableMetadata::createFromRenderArray($build);
$meta_b = BubbleableMetadata::createFromRenderArray([
'#cache' => [
'contexts' => $contexts,
'tags' => $tags,
'max-age' => $max_age,
'attachments' => $attachments,
],
]);
$meta_a
->merge($meta_b)
->applyTo($build);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttachmentsTrait:: |
protected | property | The attachments for this response. | |
AttachmentsTrait:: |
public | function | ||
AttachmentsTrait:: |
public | function | ||
AttachmentsTrait:: |
public | function | ||
BubbleableMetadata:: |
public | function |
Overrides RefinableCacheableDependencyTrait:: |
|
BubbleableMetadata:: |
public | function |
Applies the values of this bubbleable metadata object to a render array. Overrides CacheableMetadata:: |
|
BubbleableMetadata:: |
public static | function |
Creates a bubbleable metadata object from a depended object. Overrides CacheableMetadata:: |
|
BubbleableMetadata:: |
public static | function |
Creates a bubbleable metadata object with values taken from a render array. Overrides CacheableMetadata:: |
|
BubbleableMetadata:: |
public | function |
Creates a new bubbleable metadata object by merging this one with another. Overrides CacheableMetadata:: |
|
BubbleableMetadata:: |
public static | function | Merges two attachments arrays (which live under the '#attached' key). | |
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
CacheableMetadata:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function | Sets cache contexts. | |
CacheableMetadata:: |
public | function | Sets the maximum age (in seconds). | |
CacheableMetadata:: |
public | function | Sets cache tags. | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
WebformBubbleableMetadata:: |
public | function | Appends the values of this bubbleable metadata object to a render array. |