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
Initial patch- Try to find steps to reproduce on fresh site install
- Review and feedback
- RTBC and feedback
- Commit
- Release
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2913627-2-preRender-assumes-non-empty-payment.patch | 2.03 KB | mparker17 |
Comments
Comment #2
mparker17I think this issue qualifies as "Major" according to the handbook.
Here is an initial patch.
Comment #3
mparker17Oops, there are no tests for D8 yet.
Comment #4
mparker17Note 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