Skip to main content

I came across this question in the related questions sidebar on my question that seems to be the same issue with out-of-the-box core blocks: Block cache not clearing on save?Block cache not clearing on save?

The accepted answer from @4k4 on that question seems to confirm the issue, but doesn't hook in to the block save to invalidate the cache like I was thinking, but mentions, as one possible workaround, adding this to the theme:

function mytheme_preprocess_block(&$variables) {
  if ($variables['base_plugin_id'] == 'block_content') {
    $renderer = \Drupal::service('renderer');
    $renderer->addCacheableDependency($variables, $variables['content'}['#block_content']$variables['content']['#block_content']);
  }
}

I don't know if this is the best answer, but it's simple and straightforward and seems to work at the moment, though it's a wonder that this would need to be done at all. It's probably less of a hack than what I was thinking.

I came across this question in the related questions sidebar on my question that seems to be the same issue with out-of-the-box core blocks: Block cache not clearing on save?

The accepted answer from @4k4 on that question seems to confirm the issue, but doesn't hook in to the block save to invalidate the cache like I was thinking, but mentions, as one possible workaround, adding this to the theme:

function mytheme_preprocess_block(&$variables) {
  if ($variables['base_plugin_id'] == 'block_content') {
  $renderer = \Drupal::service('renderer');
  $renderer->addCacheableDependency($variables, $variables['content'}['#block_content']);
  }
}

I don't know if this is the best answer, but it's simple and straightforward and seems to work at the moment, though it's a wonder that this would need to be done at all. It's probably less of a hack than what I was thinking.

I came across this question in the related questions sidebar on my question that seems to be the same issue with out-of-the-box core blocks: Block cache not clearing on save?

The accepted answer from @4k4 on that question seems to confirm the issue, but doesn't hook in to the block save to invalidate the cache like I was thinking, but mentions, as one possible workaround, adding this to the theme:

function mytheme_preprocess_block(&$variables) {
  if ($variables['base_plugin_id'] == 'block_content') {
    $renderer = \Drupal::service('renderer');
    $renderer->addCacheableDependency($variables, $variables['content']['#block_content']);
  }
}

I don't know if this is the best answer, but it's simple and straightforward and seems to work at the moment, though it's a wonder that this would need to be done at all. It's probably less of a hack than what I was thinking.

Source Link
demarts
  • 67
  • 1
  • 8

I came across this question in the related questions sidebar on my question that seems to be the same issue with out-of-the-box core blocks: Block cache not clearing on save?

The accepted answer from @4k4 on that question seems to confirm the issue, but doesn't hook in to the block save to invalidate the cache like I was thinking, but mentions, as one possible workaround, adding this to the theme:

function mytheme_preprocess_block(&$variables) {
  if ($variables['base_plugin_id'] == 'block_content') {
  $renderer = \Drupal::service('renderer');
  $renderer->addCacheableDependency($variables, $variables['content'}['#block_content']);
  }
}

I don't know if this is the best answer, but it's simple and straightforward and seems to work at the moment, though it's a wonder that this would need to be done at all. It's probably less of a hack than what I was thinking.