CCK User Reference autocompletion integration with Realnames
bobgeier - February 22, 2009 - 22:34
| Project: | Realname User Reference Widget |
| Version: | 6.x-1.0-beta1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | guix |
| Status: | closed |
Description
In the 6.x branch would be nice.
From NancyDru "Almost all other contributed modules can properly display the Real Name if they change their code to use theme('username', ...) rather than just grabbing the user name from some object."
Perhaps it's quick?

#1
Title fix
#2
This would be really useful. Subscribing.
#3
Also look at #369334: Realname for Privatemsg autocomplete
#4
I'm working on a patch for Realname, but I have a sticky point with CCK (that's why I'm leaving this issue in CCK/Userreference).
In short how can I call another autocomplete function ? I don't see any [#autocomplete_path] in D6, in D5 it was apparent and easy to change.
Longer version :
In D5 I can see how NancyDru is modifying the autocomplete function, by changing [#autocomplete_path] where it appears.
[field_user_reference] => Array
(
[#tree] => 1
[#type] => fieldset
[#description] =>
[0] => Array
(
[user_name] => Array
(
[#type] => textfield
[#title] => user_reference
[#autocomplete_path] => userreference/autocomplete/field_user_reference
[#default_value] =>
[#required] => 0
)
)
)
...
We just have to replace userreference/autocomplete/field_(name_of_userreference_field) by a custom path like realname/userreference/autocomplete/field_(name_of_userreference_field).
In D6 I can't find any [#autocomplete_path].
[field_user_reference] => Array
(
[#theme] => content_multiple_values
[#title] => Contact
[#required] => 0
[#description] => Pas trouvé ? Ajouter une nouvelle personne dans la nouvelle fenêtre et réessayer ici.
[0] => Array
(
[#type] => userreference_autocomplete
[#default_value] => Array
(
[uid] => 31
)
[#value_callback] => userreference_autocomplete_value
[_weight] => Array
(
[#type] => weight
[#delta] => 1
[#default_value] => 0
[#weight] => 100
)
[#title] =>
[#description] =>
[#required] =>
[#weight] => 0
[#delta] => 0
[#columns] => Array
(
[0] => uid
)
[#field_name] => field_user_reference
[#type_name] => testrealname
)
)
...
Somewhat the [#autocomplete_path] is hidden in the field [#type]=>userreference_autocomplete and the callback is defined in userreference_autocomplete_process(). I don't know CCK, fields, widgets and FAPI enough to find my way here, how do I just change the function called by the UserReference Autocomplete widget ?
#5
Bump, I'm trying to get help on that one in forums, IRC but nothing so far... Hints would be very appreciated ! I'm starting to think it's NOT possible to change the autocomplete function in D6 and that I would have to create a new Userreference widget ?
#6
I've found that the only way in D6 to do the CCK User Reference autocompletion integration with Realnames is to change the autocompletion function and for this, I didn't find another way than add a new widget. I think it's better like that, because you can still use the standart CCK User Reference autocomplete widget. However it is much more code than in D5 (http://drupal.org/node/369334#comment-1515162) so I wrote a new module for this.
NancyDru, what would you prefer ? Leaving that feature in a new module or integrate the code in the Realname module ? I can do it if you want, just tell me :)
The integration with views is still basic but I don't think I'll go further, I don't need it.
#7
@guix -
I like where you're going with this module, but I can't get it to even set to a field without errors. This is a sample of the 4 errors I get each time:
* user warning: Table 'drupal.realname' doesn't exist query: SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE '%C%') AND (r.rid IN (6,5)) AND (u.status = 1) ORDER BY n.realname ASC in /home/drupal/web/apps/drupal-6.11/sites/all/modules/realname_userreference/realname_userreference.module on line 403.* user warning: Table 'drupal.realname' doesn't exist query: SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE '%Chang%') AND (r.rid IN (6,5)) AND (u.status = 1) ORDER BY n.realname ASC in /home/drupal/web/apps/drupal-6.11/sites/all/modules/realname_userreference/realname_userreference.module on line 403.
* user warning: Table 'drupal.realname' doesn't exist query: SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE '%h%') AND (r.rid IN (6,5)) AND (u.status = 1) ORDER BY n.realname ASC in /home/drupal/web/apps/drupal-6.11/sites/all/modules/realname_userreference/realname_userreference.module on line 403.
* user warning: Table 'drupal.realname' doesn't exist query: SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE '%c%') AND (r.rid IN (6,5)) AND (u.status = 1) ORDER BY n.realname ASC in /home/drupal/web/apps/drupal-6.11/sites/all/modules/realname_userreference/realname_userreference.module on line 403.
Where should this `realname` table be coming from? I have RealName installed and working for other purposes already, so I don't think it's coming from there.
Thanks,
Erik
#8
Erik, you need the latest dev of Realname (2009-Apr-22). Thanks for the comment and let me know what you think about it.
#9
@guix, I think the separate module is a better choice. The question then is it a CCK module or a RealName contrib?
#10
Now I am having another, much less severe, problem. The query being used is this -
SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE "%C%") AND (r.rid IN (6,5)) AND (u.status = 1)The problem is that I'm getting an error because the
users ualias is not appearing until the secondJOINclause, but is being referenced in the first. If I flip that query, I get the results as expected.BTW, this is the exact error -
Unknown column 'u.uid' in 'on clause' query: SELECT n.realname, n.uid, u.name FROM realname n LEFT JOIN users_roles r ON u.uid = r.uid INNER JOIN users u ON n.uid = u.uid WHERE (n.realname LIKE '%C%') AND (r.rid IN (6,5)) AND (u.status = 1) ORDER BY n.realname ASC in <blah>/drupal-6.11/sites/all/modules/realname_userreference/realname_userreference.module on line 403.Thanks again,
Erik
#11
To fill in the gaps, here is the patch I used.
--- realname_userreference.module.orig 2009-05-14 10:50:53.000000000 -0400
+++ realname_userreference.module 2009-05-14 10:51:08.000000000 -0400
@@ -372,6 +372,8 @@ function _realname_userreference_potenti
$where[] = "n.uid > 0";
}
+ $join[] = 'INNER JOIN {users} u ON n.uid = u.uid';
+
$roles = array();
if (isset($field['referenceable_roles']) && is_array($field['referenceable_roles'])) {
// keep only selected checkboxes
@@ -396,8 +398,6 @@ function _realname_userreference_potenti
}
}
- $join[] = 'INNER JOIN {users} u ON n.uid = u.uid';
-
$users = array();
$where_clause = $where ? 'WHERE ('. implode(') AND (', $where) .')' : '';
$result = db_query('SELECT n.realname, n.uid, u.name FROM {realname} n '. implode(' ', $join) ." $where_clause ORDER BY n.realname ASC", $args);
#12
@Erik : Thanks ! In fact it was a typo, but I didn't notice it as it was working on MySQL 5. Here's a patch to apply to my first .zip (and a new .zip of the whole module). Let me know if it doesn't work for you...
@NancyDru : The module is related both to CCK and Realname. I think it's too specialized to enter into CCK as a submodule. Then for "Realname contrib", did you mean a sub-module included in Realname or a real separated module ? I think this should be a real separated module, like Node Reference URL Widget (from which it's inspired). If you agree with that I'll apply for a CVS access.
#13
Looks like the new package is working in whole.
Thanks,
Erik
#14
Thanks Erik. New .zip with some additional security checks and some code cleanup. I'm applying for a CVS account and if I'm accepted, will publish this as a new module.
#15
subscribing
#16
Thank for the work, guix!
It would be great to add in widgets for select list as well.
I'll spend a bit of time this week testing.
#17
Thanks a lot for this great module! I love it!!! :)
Is it possible to make a hybrid text field like on facebook's relationship field? That means if I'm typing a name in the text field the userreference field will provide suggestions for community users as usual... and if the person is a registered community user then it will link to the user as usual. If user is not a community user the userreference field will accept the value but doesn't link to it.
I think it makes sense for functionalities like relationship statuses and events - for speakers (registered users) and guest speakers (not registered users).
Regards,
Stefan
#18
Hi and thanks for your interest !
The module is now published here : http://drupal.org/project/realname_userreference
Please add your issues there.
#19
#20
Sorry, but it does not work… But the fiel User Reference is loaded on a CCK multigroup. Is it possible there is a bug between both modules?
#21
Please post new issues to report bugs / feature requests.
Elektrorl, see #518678: Does not work with CCK multigroup ;)
#22
#23
Automatically closed -- issue fixed for 2 weeks with no activity.