Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I noticed that users other than the admin can't add blocked users to a given user-specific entity reference field. I'm not sure why this is, but I went ahead and removed that condition from the validation check query in EntityReference_SelectionHandler_Generic::validateReferencableEntities()
from EntityReference_SelectionHandler_Generic.class.php
.
/**
* Implements EntityReferenceHandler::validateReferencableEntities().
*/
public function validateReferencableEntities(array $ids) {
if ($ids) {
$entity_type = $this->field['settings']['target_type'];
$query = $this->buildEntityFieldQuery();
$query->entityCondition('entity_id', $ids, 'IN');
if ($entity_type == "user") {unset($query->propertyConditions);} // new code
$result = $query->execute();
if (!empty($result[$entity_type])) {
return array_keys($result[$entity_type]);
}
}
return array();
}
I guess I'm just looking for any comments anyone might have.
Comment | File | Size | Author |
---|---|---|---|
#16 | entityreference-allow_blocked_users-2329979-16.patch | 2.29 KB | Majk07 |
#3 | entityreference-allow_blocked_users-2329979-3.patch | 2.33 KB | cdmo |
#2 | entityreference-allow_blocked_users-2329979-2.patch | 2.9 KB | cdmo |
Comments
Comment #1
cdmo CreditAttribution: cdmo commentedI also had to change the following code:
This works, but it's hacky.
Comment #2
cdmo CreditAttribution: cdmo commentedHere's a patch that takes care of it all, I welcome any feedback. Thanks.
Comment #3
cdmo CreditAttribution: cdmo commentedRemoving some errant code in the patch that git diff picked up for some reason
Comment #6
lucas.constantino CreditAttribution: lucas.constantino commentedHello, cdmo
I found an unobtrusive way to handle access to blocked users only implementing some specific hooks:
Hope it helps someone.
Comment #7
cdmo CreditAttribution: cdmo commentedThanks lucas.constantino! I actually don't work for the group where I originally had this development need, but I forwarded your solution on to them. Thanks for the work and for sharing.
Comment #8
gbirch CreditAttribution: gbirch as a volunteer commentedThanks @lucas.constantino! Helped me a LOT! I know this is an old thread, but one question: why didn't you add a user_access() check to the query_alter function?
Comment #9
ArVar CreditAttribution: ArVar as a volunteer commentedComment #10
MustangGB CreditAttribution: MustangGB commentedComment #11
gbirch CreditAttribution: gbirch commentedSorry, why is this marked "Fixed"? I can't see any changes to the code that would solve this issue.
Comment #12
MustangGB CreditAttribution: MustangGB commented@gbirch The answer given in #7 seems like good enough info to answer this
Support request
. If you feel like this is something that would be worthwhile adding to the module, please feel free to re-open, presumably as aFeature request
.Comment #13
gbirch CreditAttribution: gbirch commented@MustangGB Thanks for clarification. Just to prevent future users from being confused, shouldn't this be "Won't fix" then, or "Postponed"?
Comment #15
Majk07 CreditAttribution: Majk07 commentedUpdate patch to work with 7.15
Comment #16
Majk07 CreditAttribution: Majk07 commentedForgot to change the relatief path, this has to work
Comment #17
Majk07 CreditAttribution: Majk07 commentedComment #18
angelamnr CreditAttribution: angelamnr commented#16 works for me.
Comment #19
pawel.traczynski CreditAttribution: pawel.traczynski as a volunteer commentedI also needed similar thing in my company where blocked user accounts were employees who don't work anymore but they had to still appear in the system (for example an employee was doing something before they left and now after they are gone, current staff still needs to see these blocked accounts everywhere where they were refferred to).
Here is my complete solution to this problem. This could probably be wrapped as a complete mini-module.