Creating unique fields like "council-officer" and "council-officer-title" in profile.module 4.7b3 does not work, while "profile_officer" and "profile_officer_title" work fine. Though the "profile_" prefix is recommended, I'm pretty darned sure that there are no fields/variables named council-officer* anywhere in the bowels of Drupal.
The reason for the renaming experiment was to have cleaner-reading URLs like: profile/council-officer-title instead of profile/profile_officer_title.
What's broken:
The fields are not accessible by name from user_profile.tpl.php unless prefixed as profile_*
My best guess is that something is hard-coded to look for the "profile_" prefix somewhere in profile.module.
Work-around:
Follow recommendations and prefix all fields in profile.module with "profile_" in the name.
Comments
Comment #1
drubeedoo commentedClarification
In user_profile.tpl.php the following does *not* work:
The following works fine:
Comment #2
Zen commentedHi drubeedoo,
The issue is not because of the profile_ prefix or the council- prefix. It is the - (hyphen) vs. the _ (underscore).
You can:
a) Use underscores and make the problem go away.
b) Use a hyphen, but access it as an array rather than an object: $user['council-officer-title'] will work whereas $user->council-officer-title won't. You will very likely need to cast your $user object into an array using: $user = (array)$user; (as an e.g.).
Hope that made sense :) I'm going to mark this as closed. Please re-open if need be.
Cheers :)
-K
Comment #3
mr700 commentedMaybe profile.module should warn (if not deny) such use of characters like '-' (and this should be a feature request)?
Comment #4
drubeedoo commentedThanks for the reply, Zen. I'm still a bit green when it comes to the innards of Drupal and PHP.
mr700 has a good point. The current explanation reads as follows:
I would suggest changing it to the following:
Thanks again for answering so quickly. I have reopened this as a minor feature request for your review. Feel free to close it again if you don't agree with the above. I won't argue the point.
Comment #5
Zen commentedNo worries drubeedoo. But I think this would be better off in the documentation rather than the actual form. This doesn't affect normal usage, and only crops up when users are either writing modules or tinkering with PHP.
You could perhaps get it mentioned somewhere here.
Just for the record, the "-" is invalid here because when you say $user->council-name, PHP thinks you are subtracting 'name' from '$user->council'. This is why '-' is invalid in variable names, as it is an arithmetic operator.
Changing Project to Documentation.
Cheers :)
-K
Comment #6
senpai commentedThis was a 4.7 issue. I quote:
I'm closing this, because it' no longer an issue, because if you're using Pathauto.module on your site, you'll never need to experiment with putting dashes in your template titles.