Recreate Author Pane functionality on comment display

Created on 17 June 2024, 10 months ago

Problem/Motivation

In D7 the Author Forum β†’ module, as used by Advanced Forum, improved the display of the user summary block on forum posts.

Proposed resolution

Recreate Author Pane display of user info on the forum topic page, i.e. a forum node page.

Remaining tasks

Recreate the Author Pane output.

User interface changes

The forum topic node page's author block will look like the Author Pane display.

API changes

n/a

Data model changes

n/a

✨ Feature request
Status

Closed: duplicate

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @DamienMcKenna
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA
  • πŸ‡ΊπŸ‡Έ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
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    WIP.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    #4 was missing some use statements, this should work.

  • Status changed to Needs work 10 months ago
  • πŸ‡ΊπŸ‡Έ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
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Moving the work back to the primary ticket.

Production build 0.71.5 2024