I'm working on a module where I needed to have non-unique names and since usernames needs to be unigue I needed something like RealNames.

I'm fetching the names myself and the only thing I needed help with was to find where those names are to be shown - which RealNames can fix for me.

But - as RealNames is currently constructed I need to modify some of RealNames' files to add support for my module - which feels wrong to me and which I think isn't a very "drupal" way of doing it. I think my module should be able to implement the support for RealName by itself.

I've therefor refactored the RealNames module into using Drupals hooks to find modules supporting it as well as for talking to those modules.

I've also added a simplified approach for modules not wanting the fields control to give names to RealName - they can use hook_realname_make() to which only the user account is sent and which returns a name. I wanted my module to have complete control over which names is given for which users - that's why I added that hook.

I'm attaching a patch for this - although I also have the changes up in a git-repository at: http://github.com/voxpelli/drupal-realname/tree/master All adjustments of the patch should and will of course be posted here and not only in the git-repository :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

voxpelli’s picture

Title: Add hooks to separate modules » Add hooks to have modules define support in themselves
FileSize
24.12 KB

New version of the patch - this time with a new option for a module to opt out of having the names cached.

The reason why I add this is that the module I'm currently implementing support for RealNames in has it's own cache and I don't want the overhead and potential conflict that comes with having two caches.

Such an option can of course also be useful if some module is using a really simple method of finding out the real name which isn't worth caching.

tobiassjosten’s picture

While I haven't reviewed the (quite massive) patch, I can certainly vouch for its functionality. It works great!

NancyDru’s picture

Couldn't the module just implement template_preprocess_username()?

voxpelli’s picture

This is not a functionality that belongs in the preprocess - this is a refactoring of the current realname_supported_modules() function to behave more like Views and other established modules does when it comes to support cross-modules relations.

Currently realname_supported_modules() is hard coded - what this patch does is that it changes that to enable all module to itself tell whether it supports realname or not. This patch also changes the currently supported modules to use this new approach instead.

Currently only realname can implement support for realname - what this patch does is that it makes it possible for other modules to support realname as well without having to hack that support into realname.

bcn’s picture

FileSize
24.9 KB

Here's a patch that's been updated against the latest version of the 6.1 branch...

voxpelli’s picture

Any update on this? Check out http://drupal.org/project/connector for a module that makes use of this patch.

coderintherye’s picture

I'm going to take a look at it, though it's fairly hefty, and while I like your approach it's a bit of a phase shift so going to take some time to think about.

coderintherye’s picture

Status: Needs review » Needs work

Current patch needs to be updated to latest version of dev branch.

root@k:/var/www/drupal-6.19/sites/all/modules/realname# patch -p0 < hook_realname.patch
patching file realname_profile.inc
patching file realname.module
Hunk #1 FAILED at 380.
Hunk #2 succeeded at 712 (offset 32 lines).
Hunk #3 FAILED at 777.
Hunk #4 FAILED at 808.
Hunk #5 FAILED at 911.
4 out of 5 hunks FAILED -- saving rejects to file realname.module.rej
patching file realname_supported.inc
patching file realname.admin.inc
patching file realname_content_profile.inc
Hunk #2 succeeded at 58 with fuzz 1.
patching file realname.api.php

voxpelli’s picture

Status: Needs work » Needs review
FileSize
24.47 KB

Did a quick port of the patch - hopefully it works good.

coderintherye’s picture

Thanks, I will try that out later this week.

voxpelli’s picture

FileSize
17.36 KB

Here's another reroll against latest dev release. I also modified this patch a bit to minimize it - whenever I could avoid indenting existing code I avoided it.

coderintherye’s picture

Assigned: Unassigned » coderintherye

Ok nice this patch is applying cleanly. I need to do some further review, but I think this could be pretty good candidate for committing into dev. Thanks much for your work on this.

coderintherye’s picture

Status: Needs review » Needs work

I'm not quite sure what's going on line 929 of realname.module
So we've taken out:

-      $load_func = $module . '_load_profile';
-      if (!function_exists($load_func)) {

and that is replaced with:

+      if (!module_hook($module, 'load_profile')) {

However, on line 926 we have:
drupal_set_message(t('The profile load function (!module) was not found.', array('!module' => $load_func)), 'error');

Which is still using $load_func and then on line 929 we have:

$load_func($account, $type);

Also still using $load_func

Perhaps, I can figure this better later, it looks to me like we need to just remove the old references and in with the new, but not quite sure. Anyways, currently producing a fatal error due to this. Would appreciate assistance voxpelli in getting it cleaned up. Thanks again for the thorough patch.

voxpelli’s picture

Status: Needs work » Needs review
FileSize
17.69 KB

Ah - of course that should be changed as well. Great that you found it!

Attached is a patch fixing that error.

coderintherye’s picture

Status: Needs review » Reviewed & tested by the community

Ok, this new patch is good. I like the approach here, and I was able to cleanly apply the patch and also cleanly use voxpelli's "Connector" module at http://drupal.org/project/connector which has an implementation of the hook in connector.module at line 131 (as of the latest 1.x dev snapshot)

I definitely think this is going to be the way to go and I'm setting this to RTBC.

However, 2 things are going to need to happen I think before we can realistically put this into realname.

1) I need to ping NancyDru and talk the patch over with her.
2) We will need to ensure cck content is enabled or something cause currently trying to use content_profile via realname will return this error: "Fatal error: Call to undefined function content_fields() in sites/all/modules/realname/realname_content_profile.inc on line 54"

content_fields() is from cck. The thing is though, #2 occurs regardless of this patch so I may need to create a separate issue for it.

coderintherye’s picture

Assigned: coderintherye » NancyDru

@NancyDru: Your thoughts on this?

nikosnikos’s picture

Status: Needs review » Reviewed & tested by the community
nikosnikos’s picture

nikosnikos’s picture

FileSize
16.98 KB

Thanks for this patch, this is exactly what I needed but...
I had a "Parameter 1 to profile_load_profile() expected to be a reference, value given in /.../includes/module.inc on line 462." error with php 5.3.

I replaced :

      if (!module_hook($module, 'load_profile')) {
        drupal_set_message(t('The profile load function (!module) was not found.', array('!module' => $module . '_load_profile')), 'error');
        return $account->name;
      }
      module_invoke($module, 'load_profile', $account, $type);

by the original call of the module_load_profile function :

      $load_func = $module . '_load_profile';
      if (!function_exists($load_func)) {
        drupal_set_message(t('The profile load function (!module) was not found.', array('!module' => $load_func)), 'error');
        return $account->name;
      }
      $load_func($account, $type);

And it works now.

Here's a patch without module_invoke...

PS. There's another issue about hooks in realname module (I saw it this morning) : #689642: hook realname alter the output before it is rendered

Status: Reviewed & tested by the community » Needs work

The last submitted patch, realname_add_hooks_5.patch, failed testing.

nikosnikos’s picture

Status: Needs work » Needs review

#19: realname_add_hooks_5.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, realname_add_hooks_5.patch, failed testing.

nikosnikos’s picture

Status: Needs work » Needs review

#14: realname_add_hooks_4.patch queued for re-testing.

nikosnikos’s picture

I tried to rebuild the last patch with a diff git.
Sorry for the noise.

jvieille’s picture

Priority: Normal » Major

Nancydru, why don't we get this committed?

  • This patch works apparently flawlessly since 2 years,
  • this module officially recommends it http://drupal.org/project/connector
  • 3 people have worked hard on it, the job is done, just commit!

why is it not even considered by Realname maintainers?

I am reactivating this because of this issue with the Ubercart addresses module
http://drupal.org/node/1249258
UC Addresses is a very important Ubercart module that allows to maintain several addresses / identity per user.
Addressing this would allow the user real name to be in sync with the First name / Last name of the default address handled by this module.

Thanks for you dedication to Drupal community - all your modules rock!

Status: Needs review » Needs work

The last submitted patch, 517844-realname_add_hooks-24-D6.patch, failed testing.

NancyDru’s picture

@jvieille: If it is marked "needs work," as it is, then it is unlikely to get committed.

coderintherye’s picture

Status: Needs work » Needs review
FileSize
11.88 KB

Patch needed a re-roll

coderintherye’s picture

Status: Needs review » Reviewed & tested by the community

Ok patch applies cleanly as noted by the test result.

Setting back to RTBC for Nancy to see about merging in.

NancyDru’s picture

Status: Reviewed & tested by the community » Needs review

Tsk, tsk, Kevin, one may not set their own patch to RTBC.

jvieille’s picture

Status: Needs review » Patch (to be ported)

After nearly 4 years to get the right patch for a validated code, I would have jumped over this useless procedure step....
this status seem the most appropriate for me.
I am probably not qualified to set this status, but reading the issue thread and the fact that the modified code is already in use by the community, I suggest this will help to finally close this issue.

NancyDru’s picture

Status: Patch (to be ported) » Fixed

Kevin, you do know you have commit authority, don't you?

This patch is committed.

coderintherye’s picture

Well, considering all it needed was a re-roll I felt RTBC was valid here, but fair enough.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.