You are here

function user_email_verification_user_view in User email verification 8

Same name and namespace in other branches
  1. 7 user_email_verification.module \user_email_verification_user_view()

Implements hook_ENTITY_TYPE_view().

File

./user_email_verification.module, line 273
User email verification hooks and alters.

Code

function user_email_verification_user_view(array &$build, EntityInterface $user, EntityViewDisplayInterface $display, $view_mode) {
  if ($user instanceof UserInterface) {
    $verification = \Drupal::service('user_email_verification.service')
      ->loadVerificationByUserId($user
      ->id());
    $verification = $verification && isset($verification['verified']) ? $verification['verified'] : 0;
    if ($display
      ->getComponent('user_email_verification_verified')) {
      $build['user_email_verification_verified'] = [
        '#type' => 'item',
        '#title' => t('Email verified'),
        '#markup' => '<span class="value">' . ($verification ? t('Yes') : t('No')) . '</span>',
        '#wrapper_attributes' => [
          'class' => [
            'user-email-verification-is-verified',
          ],
        ],
      ];
    }
    if ($display
      ->getComponent('user_email_verification_verified_date') && $verification) {
      $build['user_email_verification_verified_date'] = [
        '#type' => 'item',
        '#title' => t('Email verification date'),
        '#markup' => '<span class="value">' . \Drupal::service('date.formatter')
          ->format($verification, 'long') . '</span>',
        '#wrapper_attributes' => [
          'class' => [
            'user-email-verification-verified-date',
          ],
        ],
      ];
    }
  }
}