1

I am having trouble with the Cache API in Drupal 8. I embedded a views block with pagination through a field preprocess function into a node. When caching is off, I can normally use the pager and will always get the right results, but once caching is one, every block page (e.g. /node/1?page=2) shows the same block content rendering the pager useless.

I assume my hacky method is preventing the node cache to let the view in the field handle it's own caching, hence I always get the content from the page I visited first after clearing cache.

This is how the view is embedded:

function foo_preprocess_field(&$variables) {
  $field_name = $variables['field_name'];

  if($field_name === 'bar'){
      foreach ($variables['items'] as &$item) {
        $item['content'] = views_embed_view($item['content']['#markup']);
      }
   }
}
0

I think you need to add the pager context to item #cache

| improve this answer | |
  • Hey, I already tried $item['content']['#cache']['context'][] = 'url.query_args'– shouldn't that suffice? – alexej_d Apr 24 '15 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.