I can't find a way to display the realname in the user profile in a view mode. This would be an extra field.

Patch following.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rudiedirkx’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Status: Active » Needs review
FileSize
1.12 KB

Voila patch. Very easy.

rudiedirkx’s picture

FileSize
1.24 KB

Now with a link to the user profile, if the current user has access to that.

Status: Needs review » Needs work

The last submitted patch, 2: realname-2333459-2.patch, failed testing.

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
1.34 KB

Note to self: don't hack patches.

Attached patch is re-rolled against 1.2.

Status: Needs review » Needs work

The last submitted patch, 4: realname-2333459-4.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: realname-2333459-4.patch, failed testing.

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
1.26 KB

FFS! Last attempt!

Status: Needs review » Needs work

The last submitted patch, 8: realname-2333459-5.patch, failed testing.

rudiedirkx’s picture

FileSize
1.24 KB

This patch is unsafe. Use #29.

Now it's getting ridiculous....

rudiedirkx’s picture

Status: Needs work » Needs review
hass’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

Have you tried views field module or how was this named...?

rudiedirkx’s picture

Views field? How is that related to an extra field in the user profile?

hass’s picture

It allows you to show what you are looking for. I'm using this to show views data.

rudiedirkx’s picture

Who's talking about views??

"Extra fields" doesn't mean "more fields". It means extra_fields.

hass’s picture

It allows you to add a field to every entity and the source of the vield is a view. And this view can select the realname. See https://www.drupal.org/project/viewfield

rudiedirkx’s picture

Are you seriously talking about adding a real field to load a real view, to display a logicless name? This is THE reason extra_fields exist.... You don't create a field and a view to display a node title or created date, do you?

Did you see the patch? That's what an extra_field does. No logic, no display settings, no querying, just a simple display.

hass’s picture

I know what extra fields are. The views solution may be a bit heavy. However I wonder that you do not have the first/lastname in user fields. I'm using addressfield and it shows perfectly.

rudiedirkx’s picture

I have 3 fields that combined are the realname. Sometimes 1 of those 3 fields is shown. I can do that with the normal field display. Other times the full name (realname) is displayed. No addressfield. Realname takes care of the combination logic/pattern. Now I need to display it...

It seems a sensible addition. Whether to add it, is up to you.

Michael_Lessard_micles.biz’s picture

Feedback : this seems like a good place to quickly mention how not user-friendly the D7 version of this module has become.

D6 was more user friendly; albeit somewhat complicated: it was easy to understand how to make the real name field appear.

D7 Realname needs some clear HowTo instructions ("If needed, create a text field in Account Settings > Manage Fields. In the Real name settings, browser tokens options and use your desired field instead of core User name").

ericclaeren’s picture

Great, thanks for the patch. Will this land in a stable release soon?

rudiedirkx’s picture

@dreamlabs If you've reviewed & tested, change the issue status so the maintainer knows this one's ready to go.

ericclaeren’s picture

Assigned: Unassigned » ericclaeren
Status: Needs review » Reviewed & tested by the community

It works for me, simple fix. Could the maintainer look at this?

ericclaeren’s picture

Assigned: ericclaeren » Unassigned
Status: Reviewed & tested by the community » Needs review
ericclaeren’s picture

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

I haven't deployed this, but looking at the code, doesn't the #markup create a URL to the user account page, while being displayed on the user account page.

Not a problem as such .....

:)

Nice code though, I didn't know about the hook_field_exta_fields function

hass’s picture

Isn't there a checkplain required on the realname if I have no view permissions?

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs work

Very true!

#10 is unsafe.

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
1.31 KB
649 bytes

New patch & interdiff. #entity_type was also missing from the fake field.

rudiedirkx’s picture

Realname strips HTML tags during its update process:

  // Perform token replacement on the real name pattern.
  $realname = token_replace($pattern, array('user' => $account), array('clear' => TRUE, 'sanitize' => FALSE));

  // Remove any HTML tags.
  $realname = strip_tags(decode_entities($realname));

  // Remove double spaces (if a token had no value).
  $realname = preg_replace('/ {2,}/', ' ', $realname);

  // The name must be trimmed to 255 characters before inserting into the database.
  $realname = truncate_utf8(trim($realname), 255);

(which is WRONG IMO), so #10 isn't really unsafe, but wrong nonetheless.

hass’s picture

Status: Needs review » Needs work

Just reviewed this patch and wondered why I cannot select how to label should be shown. This should work like all other fields.

hass’s picture

Damn, we cannot make this invisible by default.

  • hass committed e6f3624 on 7.x-1.x
    Issue #2333459 by hass, rudiedirkx: Create extra field in user profile...
hass’s picture

Status: Needs work » Fixed

  • hass committed e6f3624 on 8.x-1.x
    Issue #2333459 by hass, rudiedirkx: Create extra field in user profile...
rudiedirkx’s picture

Extra fields don't have settings out of the box. They're still very useful to position fields, like in this case. I have a Sandbox I use to add settings to extra fields. https://www.drupal.org/sandbox/rudiedirkx/2501347 I don't think D8 will have this out of the box.

hass’s picture

I have read that this is already in D8, but haven't verified it myself.

rudiedirkx’s picture

Extra fields with settings?? That would be awesome, but hook_entity_extra_field_info() doesn't mention anything. Neither does EntityFieldManagerInterface::getExtraFields().

hass’s picture

No, just the default setting for visibility can be configured. This is what I'd wish to do here. Hide it by default.

rudiedirkx’s picture

Ah yes. It's still TRUE by default in D8, which is still weird, but it's better.

You can explicitly check the display settings for the extra field. If it's not explicitly enabled, it's not user-enabled. A lot of code to check something very simple...

This is what I use in Node Registration, including the comment =)

    // Find which fields to show. Unfortunately this is necessary for new extra fields, which are
    // VISIBLE by default. Crazy Drupal...
    $bundle_settings = field_bundle_settings('node', $entity->type);
    $use_view_mode = !empty($bundle_settings['view_modes'][$view_mode]['custom_settings']) ? $view_mode : 'default';
    $show_field = function($name) use ($bundle_settings, $use_view_mode) {
      return !empty($bundle_settings['extra_fields']['display'][$name][$use_view_mode]['visible']);
    };
hass’s picture

Status: Fixed » Closed (fixed)

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