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).

Comments

joao sausen created an issue. See original summary.

joao sausen’s picture

Patch with simple fix, provides an empty string instead of null as argument.

  • jsacksick committed 6652015e on 3.x
    Issue #3533961 by joao sausen: PaymentOption::getLabel() fails to build...
jsacksick’s picture

Version: 3.0.2 » 3.x-dev
Status: Active » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.