3

I'm trying to alter custom blocks contextual menu. In particular I need to remove "Configure block" and "Delete". Is there any way to achieve this?

2

2 Answers 2

3

The correct way to alter contextual links is to use hook_contextual_links_alter.

In your case, it should look something like:

function my_module_contextual_links_alter(array &$links, $group, array $route_parameters) {
  if ($group === 'block') {
    // Hide Configure Block option.
    unset($links['entity.block.edit_form']);
  }
}

The contextual links are heavily cached in the browser, therefore you need to make sure that the browser session cache is cleared - window.sessionStorage.clear(); - source.

2
  • Also note that this only works in modules; not themes.
    – NicklasF
    Commented Nov 19, 2021 at 22:30
  • The array key for Configure Block is $links['block_configure']
    – NicklasF
    Commented Nov 19, 2021 at 22:31
-1

You can by adding this to your theme's css file.

style.css

.block-configure,
.block-contentblock-delete { 
  display: none; 
}
1
  • 2
    Real Drupal way... hack it! Commented Feb 2, 2017 at 12:32

Your Answer

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

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