Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce.
1. Create a custom content block.
2. Add this block to the node using block_field.
3. Check the node page.
4. Make changes to the custom block.
5. Check the node page again.
Result: Cached version of the block without the last changes will be displayed.
Can be reproduced both as anonymous and logged in user.
Expected result:
Node (which displays the block) page cache should be invalidated when the block is updated.
The problem.
According to the current implementation cache metadata from the block content array is not merged in the field's build array.
$elements[$delta] = [
'#theme' => 'block',
'#attributes' => [],
'#configuration' => $block_instance->getConfiguration(),
'#plugin_id' => $block_instance->getPluginId(),
'#base_plugin_id' => $block_instance->getBaseId(),
'#derivative_plugin_id' => $block_instance->getDerivativeId(),
'content' => $block_instance->build(),
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$renderer->addCacheableDependency($elements[$delta], $block_instance);
Comment | File | Size | Author |
---|---|---|---|
#2 | block_field-2999660-2.patch | 2.26 KB | andreyjan |
|
Comments
Comment #2
andreyjan CreditAttribution: andreyjan at FFW commentedAttaching a patch with a fix.
Comment #3
andreyjan CreditAttribution: andreyjan at FFW commentedComment #4
andreyjan CreditAttribution: andreyjan at FFW commentedThe above patch applies on Dev version.
Comment #5
michaellander CreditAttribution: michaellander at Elevated Third commentedComment #6
michaellander CreditAttribution: michaellander at Elevated Third commentedI've tested this patch and confirmed that the cache metadata is merged/attached as expected. Thank you!
Comment #8
michaellander CreditAttribution: michaellander at Elevated Third commentedComment #10
hussainwebThank you for committing the fix. Is it possible to create a release so that we don't have to switch to dev version?
Comment #11
weseze CreditAttribution: weseze as a volunteer commentedPatch in #2 gives fatal error against alpha8 version. Attached is a corrected one.
EDIT: ignore this patch. It seemed to be issue with https://www.drupal.org/node/2855069
Would be really nice to see a new release so we can stop wasting time on all these issues and there intercompatibility... :)
Comment #12
weseze CreditAttribution: weseze as a volunteer commentedComment #13
michaellander CreditAttribution: michaellander at Elevated Third commentedThanks @weseze, I may aim to release another alpha shortly. I haven't had time to move on a number of the beta blocking issues and it doesn't seem too many others have been able to move them along either. I'd like to get them RTBC'd and rolled in before a beta. So another alpha might be the best route.
Comment #14
hussainwebThanks @michaellander. I am looking forward to the release. We will be able to switch back from dev in our project. :)