Problem/Motivation
On the referrals admin listing, the page can fatally error when a referral has not yet been redeemed and therefore has no referee_user assigned.
In normal module behavior, a referral entity is created as soon as a user visits /user/referral and a referral code is generated. At that point, the referral has a referrer_user and referral_coupon, but referee_user is still empty until another customer actually uses the code on an order.
However, Drupal\commerce_referral\Entity\ReferralListBuilder::buildRow() assumes referee_user is always present and calls label() / toUrl() on a null entity, which crashes the admin page.
Observed error:
Error: Call to a member function label() on null in Drupal\commerce_referral\Entity\ReferralListBuilder->buildRow()
Steps to reproduce
- Enable Commerce Referral and configure a valid referral type with a referral promotion.
- Grant a user permission to access their referral page.
- Log in as that user and visit /user/referral so a referral code is generated.
- Before any other user redeems that code, visit the referrals admin listing.
- The listing attempts to render the row for the new referral.
Proposed resolution
Update ReferralListBuilder::buildRow() to safely handle empty or missing user references.
Remaining tasks
None
User interface changes
The referrals admin listing would show a safe fallback label such as “Not assigned” for referrals that have not yet been redeemed, instead of crashing.
API changes
None
Data model changes
None
Issue fork commerce_referral-3581794
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
avpadernoComment #5
daniel.j commentedCreated test to demonstrate the issue "tests/src/Kernel/ReferralListBuilderTest.php".
Updated the List Builder to conditionally print '-' incases where 'referee_user' or 'refferrer_user' do not exist.
Thank you @dustin1221 for the issue. I'll merge and make a release.
Comment #6
daniel.j commentedComment #9
daniel.j commentedFix included in release https://www.drupal.org/project/commerce_referral/releases/1.0.3