Skip to content

Instantly share code, notes, and snippets.

@mecmartini
Last active April 20, 2022 21:39
Show Gist options
  • Select an option

  • Save mecmartini/ad7d712c3773d0371f838e9a6d3185a6 to your computer and use it in GitHub Desktop.

Select an option

Save mecmartini/ad7d712c3773d0371f838e9a6d3185a6 to your computer and use it in GitHub Desktop.
Drupal 8 - Disable page for content type
<?php
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_view().
*/
function mymodule_node_view(array &$build, NodeInterface $node, $display, $view_mode) {
if ($node->getType() === 'post') {
$build['#cache']['max-age'] = 0;
\Drupal::service('page_cache_kill_switch')->trigger();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment