This is a very simple module:

It lets users configure prefixes for each user role, and prepends the prefix on the usernames of the site users using hook_username_alter.

It checks for user roles order of importance, so that the proper role prefix is prepended.
The module is made for Drupal 7.

This is my sandbox:
http://drupal.org/sandbox/Fidelix/1431768

To clone:

git clone --branch master git.drupal.org:sandbox/Fidelix/1431768.git username_prefixes
cd username_prefixes

http://drupal.org/files/wPRpq[1]_1.png

Comments

Fidelix’s picture

Issue summary: View changes

Added a screenshot

afeijo’s picture

+1, cool useful module!

afeijo’s picture

Issue summary: View changes

Only local images are allowed

phoenix’s picture

Status: Needs review » Needs work

Hi Fidelix

Nice module!
But here are a few things to work on:
- Could you specify the version of drupal it is made for
- Please put your code in a feature branch and lear out the master branch: follow steps on this page
- Your files have to end with a blank line
- Please use the t() function around all your strings. E.g. 'title' => t('Username Prefixes') I see you used it later on, but you forgot in you hook_menu.
- You still have some coding standard issue:

FILE: ...al-7-pareview/sites/all/modules/pareview_temp/test_candidate/README.txt
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
17 | WARNING | Line exceeds 80 characters; contains 90 characters
22 | ERROR | Files must end in a single new line character
--------------------------------------------------------------------------------

FILE: ...iew/sites/all/modules/pareview_temp/test_candidate/username_prefix.info
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
3 | ERROR | Files must end in a single new line character
--------------------------------------------------------------------------------

FILE: ...w/sites/all/modules/pareview_temp/test_candidate/username_prefix.module
--------------------------------------------------------------------------------
FOUND 26 ERROR(S) AND 3 WARNING(S) AFFECTING 26 LINE(S)
--------------------------------------------------------------------------------
1 | ERROR | End of line character is invalid; expected "\n" but found
| | "\r\n"
2 | ERROR | Missing file doc comment
7 | ERROR | Whitespace found at end of line
17 | ERROR | Whitespace found at end of line
19 | ERROR | Whitespace found at end of line
26 | ERROR | Inline comments must end in full-stops, exclamation marks, or
| | question marks
28 | ERROR | Inline comments must end in full-stops, exclamation marks, or
| | question marks
28 | ERROR | There must be no blank line following an inline comment
29 | ERROR | Whitespace found at end of line
31 | ERROR | Concatenating translatable strings is not allowed, use
| | placeholders instead and only one string literal
31 | ERROR | The $text argument to l() should be enclosed within t() so that
| | it is translatable
34 | ERROR | Expected "foreach (...) {\n"; found "foreach (...) {\n "
35 | ERROR | Array indentation error, expected 4 spaces but found 6
36 | ERROR | Array indentation error, expected 4 spaces but found 6
37 | ERROR | Array indentation error, expected 4 spaces but found 6
38 | ERROR | Array indentation error, expected 4 spaces but found 6
39 | ERROR | Array indentation error, expected 4 spaces but found 6
40 | ERROR | Array indentation error, expected 4 spaces but found 6
41 | ERROR | Array indentation error, expected 4 spaces but found 6
42 | ERROR | Array closing indentation error, expected 2 spaces but found 4
42 | ERROR | Closing brace must be on a line by itself
48 | WARNING | Format should be "* Implements hook_foo()." or "Implements
| | hook_foo_BAR_ID_bar() for xyz_bar()."
56 | ERROR | else must start on a new line
60 | ERROR | else must start on a new line
65 | ERROR | else must start on a new line
71 | ERROR | Whitespace found at end of line
74 | WARNING | Line exceeds 80 characters; contains 88 characters
75 | WARNING | Line exceeds 80 characters; contains 84 characters
87 | ERROR | Files must end in a single new line character
--------------------------------------------------------------------------------

You can use this url to check your project again: http://ventral.org/pareview/httpgitdrupalorgsandboxfidelix1431768git

Fidelix’s picture

Thanks for the great and fast review!

- Could you specify the version of drupal it is made for

This is in the .info file. What do you mean?

- Please put your code in a feature branch and lear out the master branch: follow steps on this page

Done.

- Your files have to end with a blank line

Tried. Doesn't pass on the bot.

- Please use the t() function around all your strings. E.g. 'title' => t('Username Prefixes') I see you used it later on, but you forgot in you hook_menu.

No, I did not forget. According to docs, I shouldn't put t() there.
http://drupal.org/node/140311

I'm not being able to fix the following:

FILE: ...al-7-pareview/sites/all/modules/pareview_temp/test_candidate/README.txt
 --------------------------------------------------------------------------------
 FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
 --------------------------------------------------------------------------------
 24 | ERROR | Files must end in a single new line character
 --------------------------------------------------------------------------------

FILE: ...iew/sites/all/modules/pareview_temp/test_candidate/username_prefix.info
 --------------------------------------------------------------------------------
 FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
 --------------------------------------------------------------------------------
 4 | ERROR | Files must end in a single new line character
 --------------------------------------------------------------------------------

FILE: ...w/sites/all/modules/pareview_temp/test_candidate/username_prefix.module
 --------------------------------------------------------------------------------
 FOUND 5 ERROR(S) AND 1 WARNING(S) AFFECTING 6 LINE(S)
 --------------------------------------------------------------------------------
 1 | ERROR | End of line character is invalid; expected "\n" but found
 | | "\r\n"
 13 | ERROR | You must use "/**" style comments for a function comment
 36 | ERROR | The $text argument to l() should be enclosed within t() so that
 | | it is translatable
 48 | ERROR | Closing brace must be on a line by itself
 53 | WARNING | Format should be "* Implements hook_foo()." or "Implements
 | | hook_foo_BAR_ID_bar() for xyz_bar()."
 95 | ERROR | Files must end in a single new line character
 --------------------------------------------------------------------------------

I deliberately left this one untouched:

 36 | ERROR | The $text argument to l() should be enclosed within t() so that
 | | it is translatable

It doesn't make sense to me to "translate" menu paths. Do you want me to do it anyway?

phoenix’s picture

Hi Fidelix

- when applying for a full project, you need to mention a few things in your application to make reviewing more easy. You didn't mention the version of drupal it is made for in your issue above. Check this page: http://drupal.org/node/1011698
- The problems with the single new line character are the following. In windows a new line character is two characters (LFCR = line feed carriage return, this is the \r\n mentioned). In UNIX it is a single character (LF = Line feed, this is \n). I guess you programmed on a windows machine. Try to substitute those characters, or try to find the right settings for your editor or IDE.
- The t() function should be used in the l() function, not for the paths, but for the text of your link. If you create a link the path will end up in the href="" attribute and a text will be shown in between . That needs to be translatable.
As you see here: http://api.drupal.org/api/drupal/includes%21common.inc/function/l/7 The l() function takes a text part, a path and an optional options array.
- Line 13 I see this code:

/*
 * Implements hook_menu().
 */

This should become this:

/**
 * Implements hook_menu().
 */

- Please also read the page about Tips for a great project page. And try to add some more information on your project page.

Thanks for you clarification on why you didn't use the t() function in hook_menu. I didn't know that. I guess we can all learn :)

Fix those errors and then you can change the status back to "needs review"

Fidelix’s picture

Hello, phoenix.
Thank you for the quick response.

- The t() function should be used in the l() function, not for the paths, but for the text of your link. If you create a link the path will end up in the href="" attribute and a text will be shown in between . That needs to be translatable.

I know how to use the t() function well. But this is the line in question:
'#markup' => t('Roles are listed and chosen based on the order of importance, defined on !link.', array('!link' => l('admin/people/permissions/roles', 'admin/people/permissions/roles'))),

It does not make sense to make this translatable, does it?: "admin/people/permissions/roles"

See my point now? There are reasons why l() doesn't take the first parameter and runs it through t() every time. Markup (images) and inline paths being one of the reasons.

Fidelix’s picture

Status: Needs work » Needs review

BTW, I'm using Aptana Studio.
Configured it like instructed here: http://stackoverflow.com/questions/2318075/make-aptana-never-use-windows...

Didn't work, so I ended using dos2unix to convert the files. It passed on the tests here:
http://ventral.org/pareview/httpgitdrupalorgsandboxfidelix1431768git-7x-1x

This is the last remaining problem:

35 | ERROR | The $text argument to l() should be enclosed within t() so that
 | | it is translatable

Which is what I tried to make a point in my last message.

Fidelix’s picture

What if I make it like this? It should pass the test.

'#markup' => t('Roles are listed and chosen based on the order of importance, defined on !link.', array('!link' => l(t('Administration >> Configuration >> People >> Username Prefixes'), 'admin/people/permissions/roles'))),

phoenix’s picture

Well, I think it is not the right way. You give a link to go to that page. They will see the breadcrumb on that page. Just give your link a name. Not a whole path to follow, as they don't need to do it.
My suggestion:

'#markup' => t('Roles are listed and chosen based on the order of importance, defined on !link.', array('!link' => l(t('the config page'), 'admin/people/permissions/roles'))),
phoenix’s picture

Issue summary: View changes

Not very intelligent image blocking...

Fidelix’s picture

Thanks again, phoenix.

I have made the change as you suggested and now the module should pass all the tests on http://ventral.org/pareview/httpgitdrupalorgsandboxfidelix1431768git-7x-1x

NBZ4live’s picture

Status: Needs review » Reviewed & tested by the community

http://ventral.org/pareview/httpgitdrupalorgsandboxfidelix1431768git-7x-1x looks good
Code looks good
Tested on D7 and it works like it should

Suggestion:
I would suggest to add a configuration option for the look of the prefix. Like global separator between prefix and username

Fidelix’s picture

NBZ4live, that's a nice idea. I will implement it before releasing 1.0.

I was also thinking whether I should deal with mini-icons that prefix usernames depending on roles.
There are some use cases for that.

jthorson’s picture

You should empty out your master branch, so that people don't accidently check out the outdated code inside it ... check out step #5 on http://drupal.org/node/1127732

Fidelix’s picture

Thanks, jthorson.
It's empty now.

klausi’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +PAreview: single application approval

manual review:

  • project page is a bit short, see http://drupal.org/node/997024
  • "'access arguments' => array('access administration pages'),": this permission does not fit here. Reuse "administer users" or create your own.
  • username_prefixes_username_alter(): roles have a weight, so I think you should not take the rid into account for sorting but the role weight. user_roles() orders them by weight anyway.
  • This project is too short to approve you as git vetted user. We are currently discussing how much code we need, but everything with less than 120 lines of code or less than 5 functions cannot be seriously reviewed. However, we can promote this single project manually to a full project.

Otherwise I think this is nearly ready.

Fidelix’s picture

project page is a bit short, see http://drupal.org/node/997024

Added a bit of info.
Not much more I can do about it. The purpose of this module is very straightforward.

"'access arguments' => array('access administration pages'),": this permission does not fit here. Reuse "administer users" or create your own.

Used "administer users".

username_prefixes_username_alter(): roles have a weight, so I think you should not take the rid into account for sorting but the role weight. user_roles() orders them by weight anyway.

That's just documentation flaw. At first, I didn't know that user_roles() returned roles on (almost) proper weight order.

I have changed it to

/**
 * Implements hook_username_alter().
 * The user's main role is considered to be the one with higher weight 
 * on the roles administration page.
 */
This project is too short to approve you as git vetted user. We are currently discussing how much code we need, but everything with less than 120 lines of code or less than 5 functions cannot be seriously reviewed. However, we can promote this single project manually to a full project.

klausi, I understand, and this is a generally a good approach which I agree with.
But this module has a solid purpose/feature for community sites, and not just a simple form_alter to hide toolbar for user 1.

Besides, there are more features coming as I said before.
If that's not enough, I understand. Proceed as you desire.

Fidelix’s picture

Status: Needs work » Needs review
musikpirat’s picture

Your git url is not correct, you should use this one in the issue:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/Fidelix/1431768.git username_prefixes

How shall "Use Icons as prefixes work"? :)

I'd suggest to adjust the .info file a little bit from "Lets you add customized prefixes to your users" to "Lets you add customized prefixes to your users based on their roles".

Is there any reason why you use admin/config/people/prefix as the config url? I'd expected something lile admin/config/username_prefix.

Did you enhance your module meanwhile to break the 120 lines barrier? Automatical assignment of roles based on a number of comments would be imho pretty useful for community pages.

Fidelix’s picture

Thank you for your suggestions, musikpirat.

Your git url is not correct, you should use this one in the issue:

I did not set any git URL's, d.o did it automatically.

How shall "Use Icons as prefixes work"? :)

Assign a small icon (something like 16x16) to appear before the username of the user. Just like the text prefix, but an icon instead.

I'd suggest to adjust the .info file a little bit from "Lets you add customized prefixes to your users" to "Lets you add customized prefixes to your users based on their roles".

Done.

Is there any reason why you use admin/config/people/prefix as the config url?

Well, this feature is related to users and their roles, so I really think this is where it belongs.

Did you enhance your module meanwhile to break the 120 lines barrier?

Not yet. I'll leave it as a sandbox until I do.

Automatical assignment of roles based on a number of comments would be imho pretty useful for community pages.

This would be a nice feature, but it's not in the scope of this module. There are other modules for that (I think).

Thank you for all your suggestions!

Fidelix’s picture

Issue summary: View changes

Added version information.

ryandekker’s picture

Status: Needs review » Reviewed & tested by the community

The problem with the git URL in your initial post is that it points at the "master" branch, rather than the "7.x-1.x" branch. Since your master only has the "README.txt" file, it's not real helpful.

Looks like you haven't added the icon functionality. I could see this being a natural addition to this module, but I certainly don't think it's remotely required for the module to be helpful. This would, however, be an easy way to add a few lines to your code to push you over the 120 barrier.

I agree with your config location of "admin/config/people", though I think it would make sense to name it after your module, I think that's conventional. "admin/config/people/username_prefixes" (or perhaps "username-prefixes") is where I would expect to find it. All in all, not a big deal, just my two cents.

I do think it makes sense to increase your maxlength on the prefixes, it would increase the possible use cases.

Double checked Coder and PAReview and it looks good to me.

I'm marking this RTBC because everything is fine. Granted this is a small module, but it's currently non existent functionality; seems odd to deny access because a useful module is too lean.

patrickd’s picture

Status: Reviewed & tested by the community » Fixed

Your project page is quite uninformative, please have a look at the tips for a great project page.

Got a config-page? -> set a "configure =" in your .info to the path

Your using variables but your not deleting them when uninstalling the module <- you should fix that before creating a release

But this module looks good enough for me to be promoted.

Thanks for your contribution!

I've promoted this module to a full project and now your able to create releases.

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

As you continue to work on your module, keep in mind: Commit messages - providing history and credit and Release naming conventions.

Thanks to the dedicated reviewer(s) as well.

The project Username Prefixes has been promoted to a full project.
New URL

Now that this experimental project has been promoted, you'll need to update the URL of your remote repository or reclone it.

git remote set-url origin YOURUSERNAME@git.drupal.org:project/username_prefixes.git

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

Anonymous’s picture

Issue summary: View changes

corrected git url