Problem/Motivation

on a comment the compact-user viewmode have a "member for x months" that is hardcoded & gets outputted as a form item, which looks like some old legacy code we never came around to clean up.

besides of that it have hardcoded markup & we dont like that

Proposed resolution

print it all to a template so the themer can work with it

From user.module's user_user_view():

$build['member_for'] = array(
  '#type' => 'item',
  '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatTimeDiffSince($account->getCreatedTime()),
);

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mortendk created an issue. See original summary.

mortendk’s picture

Issue tags: +Twig, +drupaltwig
Cottser’s picture

Issue summary: View changes
Cottser’s picture

Even just removing the '#type' => 'item' would at least improve things slightly. Would be curious to know why that is there, the most recent change around this code looks like it was in #2250015: Improper use of a LABEL for user profile, this is where the hardcoded markup was added.

Cottser’s picture

This one is also very related, changed it from 'user_profile_item' to 'item'.

So it looks like it would have been printed via user-profile-item.tpl.php which had DL markup.

Relevant note from @David_Rothstein in #1291100-28: Remove category system from user edit and view:

Why is this being themed as a form item when it's not displayed inside a form? (Side effect: The "Member for" pseudo-field now has a noticeably different font size than an actual user field, when they are displayed on the user's profile. Not that the previous theming was great either, though.)

From @David_Rothstein again in #1291100-35: Remove category system from user edit and view:

I think '#type' => 'item' is also still wrong, but not sure there's a good alternative currently, so we can leave it for a followup.

mortendk’s picture

as a dirty hack i sepeated the date out based on the h4 tag thats there

user--compact.html.twig file

{{ content.user_picture }}

{#  remove markup hardcoded in D8.0 #}
{% set member_for_date = content.member_for['#markup']|split('</h4>') %}
{{ member_for_date.1 }}

{{ content|without('user_picture', 'member_for') }}

we should offcourse fix this for real but at least this is a way to get around it & still get the date out, even that we cant do anything with it.

or take it from the user picture and generate the date strings

{{ content.user_picture['#object'].getCreatedTime|date('d.M y') }}

Cottser’s picture

I can't think of a clean way to remove it from template land but there is a workaround in preprocess land:

/**
 * Implements hook_preprocess_HOOK() for user templates.
 */
function MYTHEME_preprocess_user(&$variables) {
  // Don't render "member for" as a form element.
  unset($variables['content']['member_for']['#type']);
}
andypost’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.