Components under user_email_verification_user_view() are affected by cache

Created on 20 September 2022, almost 2 years ago
Updated 6 July 2023, 12 months ago

Problem/Motivation

In a website i have started using this module, i have noticed that when one user registers and logs in (without validate yet the email)
in their user page (/user), the field where i can see the state of the verification says "No" (as expected, mail is not verified)

After verifying the mail user gets redirected to the same page, but the field still says "No"
After performing 'drush cr', field value is changed to "Yes"

Not sure if this is just in my case (local site, ddev and cache configuration), or is a general issue, but if I apply the solution i propose below, the field's value is updated properly without CR

Steps to reproduce

Explained above

Proposed resolution

in user_email_verification.module, under the function user_email_verification_user_view() (line 66), add a '#cache' key to the elements that are being built:

    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']],
        '#cache' => [
          'contexts' => [
            'user_email_verification_needed',
          ],
        ],
      ];
    }

    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']],
        '#cache' => [
          'contexts' => [
            'user_email_verification_needed',
          ],
        ],
      ];
    }

Remaining tasks

Create patch
Test if this issue happens to other people

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium gorkagr

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024