Problem/Motivation

\Drupal\payment_reference\Plugin\Field\FieldType\PaymentReference::preSave() has code which reads:

$payment_line_items_currency = $this->currencyStorage->load($payment_line_items->getCurrencyCode());
$element['table']['payment_total'] = array(
    /* ... */
  'total' => array(
    '#markup' => $payment_line_items_currency->formatAmount($payment_line_items->getAmount()),
  ),
);

Note that the $payment_line_items variable's name is misleading — it actually contains a \Drupal\payment\Entity\Payment object.

The code above works fine when $payment_line_items has at least one line item; but if you try to display a Payment Reference field that does not reference any payments, $payment_line_items contains a payment object that does not have a currency code, so $payment_line_items->getCurrencyCode() returns an empty string, which means that $payment_line_items_currency ends up being NULL, and the call to $payment_line_items_currency->formatAmount() fails.

Proposed resolution

Check that $payment_line_items_currency is not NULL before trying to output the payment total row.

Note that the code from #2 has been added as a pull request to this project's mirror at https://github.com/bartfeenstra/drupal-payment/pull/39

Remaining tasks

  1. Initial patch
  2. Try to find steps to reproduce on fresh site install
  3. Review and feedback
  4. RTBC and feedback
  5. Commit
  6. Release

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mparker17 created an issue. See original summary.

mparker17’s picture

Assigned: mparker17 » Unassigned
Priority: Normal » Major
Issue summary: View changes
Status: Active » Needs review
FileSize
2.03 KB

I think this issue qualifies as "Major" according to the handbook.

Here is an initial patch.

mparker17’s picture

Issue summary: View changes

Oops, there are no tests for D8 yet.

mparker17’s picture

Issue summary: View changes

Note that the code from #2 has been added as a pull request to this project's mirror at https://github.com/bartfeenstra/drupal-payment/pull/39