You are here

public function BlocacheMetadata::setOverrides in Blocache (Block Cache Control) 8

Set the overwritten cache metadata.

Return value

bool Returns TRUE if the cache metadata has been setted; FALSE, otherwise.

File

src/BlocacheMetadata.php, line 157

Class

BlocacheMetadata
Class BlocacheMetadata.

Namespace

Drupal\blocache

Code

public function setOverrides(int $max_age, array $contexts, array $tags) {
  if (!$this
    ->isBlock()) {
    return FALSE;
  }
  $metadata = [
    self::METADATA_MAX_AGE => $max_age,
    self::METADATA_CONTEXTS => array_filter($contexts),
    self::METADATA_TAGS => array_filter($tags),
  ];
  $this->overridden = TRUE;
  $this->overrides = $metadata;
  $this->block
    ->setThirdPartySetting(self::MODULE, self::OVERRIDEN, TRUE);
  $this->block
    ->setThirdPartySetting(self::MODULE, 'metadata', $metadata);
  return TRUE;
}