0

I'm on Drupal 8.

I'm writing a module where I want to have custom entity which will reuse Block's visibility mechanism.

I don't want custom block type, I don't want my custom entities to appear as blocks in block system.

I want it to be separate entity type where users will store some third party inline Javascript code and they will have control on where this code might be loaded. (like embedding some third party services).

As in block's visibility settings, they might choose it to load:

  • On specified paths.
  • On specified content types.
  • For specified user roles.

I have tried many things, I already implemented this functionality using custom blocks but in that case I had to alter block system to hide my custom blocks from it.

What I'm looking for now is the right way of extending Block's functionality so that I can reuse visibility settings part for custom entity type.

  • 1
    The "visibility" as you call it is are just contexts(plugins). Have a look at \Drupal\block\BlockForm::buildVisibilityInterface – user21641 Jan 21 '16 at 7:52
  • 1
    At the moment, trying to re-use condition plugins will cause any condition plugin to be displayed for Blocks. The Rules module ran into this trying to re-use that plugin type. You will need to re-implement a condition plugin system yourself. – mradcliffe Jan 21 '16 at 16:10

Your Answer

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

Browse other questions tagged or ask your own question.