function template_preprocess_commerce_payment_method in Commerce Core 8.2
Prepares variables for payment method templates.
Default template: commerce-payment-method.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An associative array containing rendered fields.
- attributes: HTML attributes for the containing element.
File
- modules/
payment/ commerce_payment.module, line 110 - Provides payment functionality.
Code
function template_preprocess_commerce_payment_method(array &$variables) {
/** @var Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $variables['elements']['#commerce_payment_method'];
$variables['payment_method_entity'] = $payment_method;
$variables['payment_method'] = [
// The label is generated dynamically, so it's not present in 'elements'.
'label' => [
'#markup' => $payment_method
->label(),
],
];
foreach (Element::children($variables['elements']) as $key) {
$variables['payment_method'][$key] = $variables['elements'][$key];
}
}