11

From the Drupal 8 administration, I configured a block (block created from a custom module) for display it in /user/* pages.

enter image description here

It works; I see this block in /user/* and /user/*/edit pages. Now, I want to display my block only from /user/* pages (the view mode), not from /user/*/edit pages (the edit mode).

Can I do that from the Drupal Administration page? I tested it adding "!/user/*/edit" but this has no effect.

enter image description here

If I can't, how can I do that from my custom module?

5
  • Try using /user/*/view instead.
    – Eyal
    Commented Oct 22, 2016 at 0:15
  • Not work ;) with "/user/*/view", the block not showed from /user/4 or /user/4/edit by example Commented Oct 22, 2016 at 0:24
  • It could be that this condition plugin is too simple for your use case. Fortunately it is fairly easy to create a custom condition plugin in drupal 8.
    – Eyal
    Commented Oct 22, 2016 at 0:28
  • I think too..what is a good way for manage this case from a custom module ? The block is already defined from my custom module in a Block Class Commented Oct 22, 2016 at 0:32
  • 1
    You can write your own condition plugin class. It has a method that returns true if the block should be visible.
    – Eyal
    Commented Oct 22, 2016 at 7:55

7 Answers 7

10

If you use this module then the exclamation prefix would work to exclude paths: https://www.drupal.org/project/block_exclude_pages

8

For Drupal 8 install the Route Condition Module and use the entity.user.canonical condition.

1

For drupal 7 users you can use Context module and simple add page to path /user/* and ~/user/*/edit/ to exclude edit page.

0

If it's your own custom block plugin, you can have your build function return null on node edit pages.

0

There is a module called Route Condition that allows you to specify exact routes (pages) to display blocks on. So for the user profile page the route would be user.entity.canonical (which is actually the example on the module page.

-1

sometimes block display settings are all you need

Block displays are set per theme. You can sometimes simply disable the block on the theme used for /*/edit pages and leave it enabled on the theme used for /user/ pages.

If your site is set up this way, you can avoid extra modules, custom code and complex workarounds.

example

On a site using Claro as the admin theme (for other themes just substitute the name in the path):

  • visit /admin/appearance to confirm there's a check in the box labeled "Use the administration theme when editing or creating content" (if not, see note below)
  • visit /admin/structure/block/list/claro and disable the unwanted blocks
  • visit /admin/structure/block (the default theme block settings page) to confirm that the same blocks are still enabled

With this configuration they show at /user/ but not at /user/edit.

note

If your site doesn't already use the admin theme when editing or creating content, checking the box will change the display of all add/edit pages (e.g. node/add/page and node/123/edit). Have a look at all add/edit pages if you make this change, as it may cause some changes you'd need to address separately, like adjusting theme templates.

-3

Why don't you try just to hide on the pages you don't want it to be displayed instead of using "Show for the listed pages"? Change the option with "Hide for the listed pages" and add there user/*/edit and every other page where you don't want that block to be displayed.

1
  • and every other page: that would be a lot of pages!
    – daniels
    Commented May 16, 2017 at 15:55

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.