- Issue created by @DamienMcKenna
- πΊπΈUnited States DamienMcKenna NH, USA
Some details that are needed:
/** * Implements hook_entity_extra_field_info(). */ function forum_entity_extra_field_info() { $fields['user']['user']['display']['current_status'] = [ 'label' => t('Current status'), 'description' => t("Whether the user is currently logged in."), 'weight' => 3, ]; $fields['user']['user']['display']['username'] = [ 'label' => t('Username'), 'description' => t("The user's raw username."), 'weight' => 4, ]; $fields['user']['user']['display']['joined'] = [ 'label' => t('Joined'), 'description' => t("When the user joined the site."), 'weight' => 6, ]; $fields['user']['user']['display']['last_seen'] = [ 'label' => t('Last seen'), 'description' => t("When the user was last seen on the site."), 'weight' => 7, ]; $fields['user']['user']['display']['contact_link'] = [ 'label' => t('Contact link'), 'description' => t("Link to the user's contact form."), 'weight' => 8, ]; return $fields; } /** * Implements hook_ENTITY_TYPE_view() for user entities. */ function forum_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display) { if ($account->isAuthenticated()) { if ($display->getComponent('current_status')) { $build['current_status'] = [ '#type' => 'item', '#markup' => $account->isActive() ? t('active') : t('inactive'), ]; } if ($display->getComponent('username')) { $username = [ '#theme' => 'username', '#account' => $account, ]; $build['username'] = [ '#type' => 'item', '#markup' => \Drupal::service('renderer')->render($username), ]; } if ($display->getComponent('joined')) { $build['joined'] = [ '#type' => 'item', '#markup' => '<p><span class="label">' . t('Joined:') . '</span> ' . \Drupal::service('date.formatter')->format($account->getLastLoginTime()) . '</p>', ]; } if ($display->getComponent('last_seen')) { $build['last_seen'] = [ '#type' => 'item', '#markup' => '<p><span class="label">' . t('Last seen:') . '</span> ' . \Drupal::service('date.formatter')->formatTimeDiffSince($account->getLastLoginTime()) . '</p>', ]; } if ($display->getComponent('contact_link')) { $build['contact_link'] = [ '#type' => 'item', '#markup' => '<p>' . $account->toLink('Contact', 'contact-form')->toString() . '</p>', ]; } } }
- Status changed to Needs review
10 months ago 5:46pm 17 June 2024 - πΊπΈUnited States DamienMcKenna NH, USA
#4 was missing some use statements, this should work.
- Status changed to Needs work
10 months ago 9:03pm 17 June 2024 - πΊπΈUnited States DamienMcKenna NH, USA
To make the display work I've found that adding the fields to the "compact" view mode is a start, then making changes to the comment.html.twig template as needed.
- Status changed to Closed: duplicate
10 months ago 9:04pm 17 June 2024 - πΊπΈUnited States DamienMcKenna NH, USA
Moving the work back to the primary ticket.