I want to generate about 40 buttons on the same page, every button should be visible to only a certain group of people based on their Drupal roles.

What the best way to do it ? I thought about creating a bloc for every button but to display them with visibility restriction in the Block layout and restrict every bloc by role..but it's not very efficient and the Block layout page will be full of those blocs.

Does anyone have any suggestions ?

Thank you


you can simply create different class for each type color and based on the role you can add the class to the button.

| improve this answer | |
  • 1
    Hi @Gaurav, could you elaborate your answer with some snippets of code to guide OP in the right direction? At least try to provide the different hooks and theme functions. Thanks! – Wim Mostrey Mar 8 '17 at 12:03
  • @Gaurav Rajdeo, I don't really understand how i can link between the class and the role ? Could you elaborate ? Many thanks – usethe23 Mar 8 '17 at 12:38
  • I would want to know what is your approach to create your buttons. Are you going to do it with forms? – Gaurav Rajdeo Mar 9 '17 at 7:21
  • It would be easier I guess with the forms because you can add your html elements such as <div class="button_1"></div> in $form['button_1']['#prefix'] and $form['button_1']['#suffix']. So now according to this class you can write css 'background-color' property for each button. – Gaurav Rajdeo Mar 9 '17 at 7:35

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.