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

zengenuity created an issue. See original summary.

gregaltuna’s picture

Hear, 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.

sinasalek’s picture

Same problem here.
For now it can be fixed by added the following code to "function bean_block_view" at bean.module

  if (!empty($return['content']) && module_exists('contextual') && entity_access('edit', 'bean', $bean) && $bean) {
    $return['content']['#contextual_links']['bean'] = array(
      'block', array($bean->Identifier(), 'edit')
    );
  }
guistoll’s picture

Assigned: Unassigned » guistoll
Status: Active » Needs review
Issue tags: +issue
StatusFileSize
new393 bytes
new393 bytes

Thanks @sinasalek for this code.

Here's a patch for this.

The last submitted patch, 4: bean-contextual-links-issue-2991960-4-d8.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 4: bean-contextual-links-issue-2991960-4-d8.patch, failed testing. View results

guistoll’s picture

peter.alserda’s picture

Version: 7.x-1.13 » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community
indytechcook’s picture

The 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?

laurelstreng’s picture

I'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?

gregaltuna’s picture

@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.

nedjo’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (won't fix)

While 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:

/**
 * 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']
    ];
  }
}