Problem/Motivation
#2084823: contextual links for entity view changed the way that contextual links are added to BEANs. On some sites, this change led to contextual links no longer displaying on BEAN blocks.
Workaround
One option to restore the previous behaviour without patching is to implement hook_block_view_alter() in a custom module:
/**
* Implements hook_block_view_alter().
*
* Conditionally adds contextual links.
*
* @see https://www.drupal.org/project/bean/issues/2991960
*/
function mymodule_block_view_alter(&$data, $block) {
if (!module_exists('contextual')) {
return;
}
$bean = bean_load_delta($block->delta);
$bean_is_viewable = entity_access('view', 'bean', $bean) && $bean;
$block_has_content = !empty($data['content']);
if ($bean_is_viewable && $block_has_content) {
$data['content']['#contextual_links']['bean'] = [
'block', [$bean->Identifier(), 'edit']
];
}
}
Original issue report
After upgrading from 7.x-1.11 to 7.x-1.13, I no longer have the Edit Block contextual link on my Bean-created blocks. I would guess this is related to changes in #2084823: contextual links for entity view.
Comments
Comment #2
gregaltuna commentedHear, hear. Same thing happened to me. I copied a bunch of module folders from my distro and pasted into a fresh install... then went and drush'd my updates. I went in and created my first feature Bean, and the contextual "Edit Block" link isn't there.
I reverted back to 1.11 and had no problems. Will keep an eye for a patch.
Comment #3
sinasalek commentedSame problem here.
For now it can be fixed by added the following code to "function bean_block_view" at bean.module
Comment #4
guistoll commentedThanks @sinasalek for this code.
Here's a patch for this.
Comment #7
guistoll commentedComment #8
peter.alserda commentedComment #9
indytechcook commentedThe code in this patch was moved in this commit: https://cgit.drupalcode.org/bean/commit/?id=67ef69c. Are you using custom bean plugins with override the view method? Or perhaps some contrib modules which provide bean plugins?
Comment #10
laurelstreng commentedI'm actually curious to look into this. I'm running into the exact same issue and implementing the patch did fix the problem.
If the code in the patch is still in the module then something else (maybe another module) might be conflicting?
Comment #11
gregaltuna commented@indytechcook I actually created a feature that uses Bean to create hero features. I don't want to patch the module, because we have it deployed to 350+ sites that could be running different versions. So as for the distro we have set up, I made them stick with 7.x-1.11 until patch is verified locally. We can't seem to verify/confirm locally.
Comment #12
nedjoWhile this is a regression for some sites, it results from changes in #2084823: contextual links for entity view that benefitted other sites or use cases and at this point is unlikely to be rolled back. Hence marking won't fix.
One option to restore the previous behaviour without patching is to implement
hook_block_view_alter()in a custom module: