Problem/Motivation

A few sites I support behind an Akamai caching service have reported having their H1 headings displaying as "Access Denied" to public users.

One site is running ver 1.4.5, the other I can't confirm but appears to be a newer version.

Steps to reproduce

  1. Using CivicTheme, as a content author, create a page in Draft.
  2. View the page at the live URL to trigger the page to be cached.
  3. Publish the page.
  4. Visit the page as a non-authenticated user

Proposed resolution

A potential fix could be adding a preprocess to include some CacheContext as exampled in this issue from Bootstrap: https://www.drupal.org/project/bootstrap/issues/3240459

CommentFileSizeAuthor
#8 publish.png1.16 MBsonam.chaturvedi
#8 draft.png1.59 MBsonam.chaturvedi

Comments

Toby Wild created an issue. See original summary.

toby wild’s picture

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;
  }
}
toby wild’s picture

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;
  }
}

fionamorrison23’s picture

Assigned: Unassigned » joshua1234511
Issue tags: -cache +civictheme-release-1.7

alex.skrypnyk’s picture

Title: Page titles cached as Access Denied » Banner shows page titles as "Access Denied" due to a block cache
alex.skrypnyk’s picture

Assigned: joshua1234511 » sonam.chaturvedi
Status: Active » Needs review
sonam.chaturvedi’s picture

Assigned: sonam.chaturvedi » alex.skrypnyk
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.59 MB
new1.16 MB

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 - PASS

Screenshots:
unpublished content as an anonymous user
test

published content as an anonymous user
test2

alex.skrypnyk’s picture

Status: Reviewed & tested by the community » Fixed

Implemented, tested and will be released in 1.7

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.