Bringing Account Age Back to Drupal 12 User Profiles

Content
Image
Illustration d’un profil utilisateur accompagné d’un calendrier et d’une horloge, représentant le temps écoulé depuis la création du compte. / Illustration of a user profile beside a calendar and clock, representing the time since the account was created.

With each new release, Drupal continues to retire older features and improve how core handles them. When a feature I use disappears, I usually look for a contributed replacement. Sometimes, though, the replacement is already in core under a different name.

That is what happened with “Member for” on user profiles. On a fresh Drupal 12 Standard installation, the account name appears at the top of the profile page, but there is no account age beneath it. I liked seeing that information, so I looked into bringing it back.

The old Member for display is deprecated. Its markup was hard-coded, which made it difficult to theme consistently with other fields. It also had accessibility and caching issues. Drupal’s recommended replacement is the user account’s Created field, which is now available on the profile’s Manage display page.

To use it, go to People → Account settings → Manage display and move Created out of the hidden fields. Select the Select the Time ago formatter and enable Display as a time difference.

I tested the display both with and without the “ago” suffix. Without it, the value describes how long the account has existed: “29 minutes 52 seconds.” With it, the value describes when the account was created: “29 minutes 52 seconds ago.” I prefer the second version on a profile page. It also fits the Created label, so I can leave that label as it is. Use @interval ago as the formatter’s past format to get this result.

If your site was upgraded, the old Member for display may still be visible. Drupal plans to remove it in Drupal 13, so this is a good time to switch your profile display to Created. The information is still there; it just uses a standard field that you can configure and theme like other profile fields.

Catégorie