Describe your bug or feature request.
TypeError: Drupal\commerce_payment\PaymentOption::getLabel(): Return value must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup returned in Drupal\commerce_payment\PaymentOption->getLabel() (line 88 of modules/contrib/commerce/modules/payment/src/PaymentOption.php).
The code in question is:
$card_number = $payment_method->card_number->value;
$args = [
'@card_type' => $card_type,
'@card_number' => $card_number,
];
return $card_number ? $this->t('@card_type ending in @card_number', $args) : $this->t('@card_type', $args);
If the $card_number is null it fails because t() expects arguments even though @card_number is not being rendered.
Trying to convert to string returns:
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /app/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of core/lib/Drupal/Component/Utility/Html.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | commerce-3533961-1-payment-option-getlabel-fails-to-build-label.patch | 705 bytes | joao sausen |
Comments
Comment #2
joao sausen commentedPatch with simple fix, provides an empty string instead of null as argument.
Comment #4
jsacksick commentedCommitted, thanks!