You are here

public function NextPreviousBlock::getCacheTags in Next Previous Post Block (Node or Page Pagination) 8.5

Same name and namespace in other branches
  1. 8 src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::getCacheTags()
  2. 9.0.x src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::getCacheTags()
  3. 1.0.x src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return value

string[] A set of cache tags.

Overrides ContextAwarePluginBase::getCacheTags

File

src/Plugin/Block/NextPreviousBlock.php, line 157

Class

NextPreviousBlock
Provides a 'Next Previous' block.

Namespace

Drupal\nextpre\Plugin\Block

Code

public function getCacheTags() {

  // Get the created time of the current node.
  $node = $this->routeMatch
    ->getParameter('node');
  if (!empty($node) && $node instanceof NodeInterface) {

    // If there is node add its cachetag.
    return Cache::mergeTags(parent::getCacheTags(), [
      'node:*',
    ]);
  }
  else {

    // Return default tags instead.
    return parent::getCacheTags();
  }
}