0

We're using blocks and Beans throughout a very large site. The issue is that the contextual links have "Configure Block" which takes you to the block configuration page for that particular block, and another contextual links labeled "Edit Block".

The "Edit Block" link is the correct link as it brings the user to the Bean admin page for that block with fields and settings.

I'm not able to find the hook to alter that main "Configure Block" link or text.

I've tried:

hook_menu_link_alter() hook_contextual_links_view_alter() hook_menu_contextual_links_alter() hook_block_view_alter()

None of these seem to expose the "Configure Block" text or URL.

I've also tried the Custom Contextual Link module, but it doesn't allow you to edit or remove this link.

I am not interested in hiding it with styling. That isn't fixing the problem. I want to programmatically alter that one contextual link.

1 Answer 1

0

I was able to accomplish this for Panels by using the following:

/**
 * Implements preprocess_panels_pane().
 */
function hook_preprocess_panels_pane(&$vars) {  
  if ($vars['pane']->type == 'panels_mini') {
    unset($vars['admin_links']);
    $vars['admin_links'] = '';
  } 

  // Load the currently logged in user.
  global $user;

  if ($vars['pane']->type == 'block') { 

    // Check if content array is set
    $type = isset(array_keys($vars['content'])[0]) ? array_keys($vars['content'])[0] : '';

    // Check if the pane subtype is a bean
    if (strpos($vars['pane']->subtype, 'bean-') !== false) {

      // Get path of bean edit link
      $path = isset(array_keys($vars['content']['bean'])[0]) ? array_keys($vars['content']['bean'])[0] : '';
      unset($vars['admin_links']);

      // Check if the user has the 'administrator' or 'content editor' role.
      if (in_array('administrator', $user->roles)) {
        $vars['admin_links'] = '<div class="contextual-links-wrapper"><ul class="contextual-links"><li class="bean-  last"><a href="/block/' . $path . '/edit?destination=">Edit Block</a></li></ul></div>';     
      } else {
        $vars['admin_links'] = '';
      }     
    }         
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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