- Issue created by @Toby Wild
- 🇦🇺Australia Toby Wild
Adding a pre_process function to the theme should fix this.
function <THEMENAME>_preprocess_block(&$variables) { if ($variables['configuration']['label'] && $variables['configuration']['label'] == 'Banner') { $variables['#cache']['contexts'][] = 'user'; if ($variables['base_plugin_id'] != 'block_content') { return; } /** @var \Drupal\node\Entity\Node $node */ $node = \Drupal::routeMatch()->getParameter('node'); $block = $variables['elements']['content']['#block_content']; // If the node is not loaded, adjust the cache max-age of the banner block to -1. if ($block && $block->bundle() == 'civictheme_banner' && !$node) { $variables['#cache']['max-age'] = 0; } }
- 🇦🇺Australia Toby Wild
Clarifying my above suggestion:
/** * Preprocess block function to add additional cache context on Banner block. */ function <THEMENAME>_preprocess_block(&$variables) { if ($variables['base_plugin_id'] != 'block_content') { return; } $node = \Drupal::routeMatch()->getParameter('node'); $block = $variables['elements']['content']['#block_content']; // If the node is not loaded, adjust the cache max-age of the banner block to -1. if ($block && $block->bundle() == 'civictheme_banner' && !$node) { $variables['#cache']['max-age'] = 0; } }
- Assigned to joshua1234511
- Assigned to sonam.chaturvedi
- Status changed to Needs review
10 months ago 5:03am 7 March 2024 - Assigned to alex.skrypnyk
- Status changed to RTBC
9 months ago 6:37am 15 March 2024 - 🇮🇳India sonam.chaturvedi Pune
Verified and tested on 1.x-dev
Testing Results:
1 View the unpublished content as an anonymous user : The banner title shows Access denied - PASS
2 View the published content as an anonymous user : The banner title does not show access denied and it shows page title - PASSScreenshots:
unpublished content as an anonymous user
published content as an anonymous user
- Status changed to Fixed
9 months ago 10:33pm 18 March 2024 - 🇦🇺Australia alex.skrypnyk Melbourne
Implemented, tested and will be released in 1.7
Automatically closed - issue fixed for 2 weeks with no activity.