reference_blocked_users
Small Module, Big Headache Relief for Editorial Settings
This is a small module but it will save you a big headache, especially in editorial settings.
There are two places you'll be looking for entity reference users:
Authored By Field
The first field is "authored by", found under authoring information. It's available in any content type you create. In order to see that field as a content editor, you must have the permission to "administer content".
Custom Entity Reference User Field
The second place where you will need to reference users is to add a custom field in a content type as an entity reference user. This field has a configuration form that asks you to fill out "reference method", "filter by", and "sort by".
In Drupal core, /core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php this plugin provides the entity selection for the user. In order to view all users, blocked/active, you must have the permission "administer users".
if (!$this->currentUser->hasPermission('administer users')) { $query->condition('status', 1); }
Why Did I Create This Module?
I want content editors to have the ability to reference all users (blocked and active) in the Authored by field or in any custom entity reference user field.
There is some work available on Drupal to create a patch that gives you the ability to include the blocked users in the configuration form for the custom field. But, there is no solution for the "authored by" field, because the authored by field does not have a configuration form. Read more about the issue here.
I wanted one solution for both scenarios (the "Authored by" and the custom entity reference user"). The solution is to create a custom permission that can be assigned to any role in the system, that allows that role to reference all users (blocked and active). That's what this module does.
Testing Process
Login as an Admin and Create Four Users and One Role
Install the module and apply the permission to the editor role.
Create Two Entity Reference User Fields Inside Article Content Type
We are testing the configuration and the new permission.
First Field: Include Anonymous User and All Roles in the Configuration Form
Second Field: Exclude Anonymous User and Filter by Editor Role Only in the Configuration Form
Logout and Sign In as an Editor and Try to Add or Edit an Article
For Authored By Field, the Field Will Reference All Users
For the First New Added Field, the Field Will Reference All Users
For the Second New Added Field, the Field Will Reference All Editors
Developed & Designed By: Alaa Haddad
A Personal Thank You for Your Support
Every project you see here, including this one, reflects countless hours of work driven by my passion for making Drupal better for everyone. Your support truly makes a difference, and there are a few simple ways you can help these projects grow and reach others who might benefit:
- Use & Share Feedback: Have you found this project (or any of my other work) helpful? Let me know what worked well or how it could be improved. Real user input drives better tools for the entire community.
- Click "Like" on Drupal.org: It may seem small, but liking this project on Drupal.org helps others discover and trust these tools.
- Spread the Word: Share these projects on social media, Slack groups, or anywhere Drupal folks connect. Your word of mouth helps these tools find the people who need them.
- Explore More of My Work: Check out my other projects on Drupal.org to see what else might support your workflow or inspire your next build.
W3CSS Theme (d8w3css) - Solo - W3CSS Paragraphs - Paragraphs Bundles - Amun - Amunet - Anhur - Acquia Purge Varnish - Cloudflare Purge - Reference Blocked Users - Solo Copy Blocks - Solo Utilities - PB Import - VVJA - Accordion - VVJC - 3D Carousel - VVJB - Basic Carousel - VVJF - 3D FlipBox - VVJH - Hero - VVJL - Lightbox - VVJP - Parallax - VVJR - Reveal - VVJS - Slideshow - VVJT - Tabs - Module Matrix - Selectify - Utilikit
If you have any questions, ideas, or feedback about my Drupal.org projects, I’d love to hear from you! To keep things open and helpful for the entire community, I encourage you to post directly in the project's issue queue on Drupal.org. This way, your questions and the answers can benefit others who may have the same needs.
At the end of the day, my goal is to make Drupal easier and more enjoyable for everyone, especially small businesses and site builders who want to create professional sites without extra hassle. Together, we can build something even better. Thank you for your support, and for being part of this journey!