2

I am trying to restrict access to the block to be accessible only on the route:entity.user.canonical route.

Is it possible to define that on the block edit form?

4

There is no UI for it, but you can either write your own condition plugin to do that or implement hook_block_access() like this:

function yourmodule_user_block_access(BlockInterface $block, $operation, AccountInterface $account) {

  $hidden_blocks = ['yourtheme_block_id'];
  $hidden_routes = ['entity.user.canonical'];

  if ($operation == 'view' && in_array($block->id(), $hidden_blocks) && in_array(\Drupal::routeMatch()->getRouteName(), $hidden_routes)) {
    return AccessResult::forbidden();
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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