You are here

function template_preprocess_commerce_promotion in Commerce Core 8.2

Prepares variables for promotion templates.

Default template: commerce-promotion.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/promotion/commerce_promotion.module, line 78
Provides a UI for managing promotions.

Code

function template_preprocess_commerce_promotion(array &$variables) {

  /** @var Drupal\commerce_promotion\Entity\PromotionInterface $promotion */
  $promotion = $variables['elements']['#commerce_promotion'];
  $variables['promotion_entity'] = $promotion;
  $variables['promotion_url'] = $promotion
    ->isNew() ? '' : $promotion
    ->toUrl();
  $variables['promotion'] = [];
  foreach (Element::children($variables['elements']) as $key) {
    $variables['promotion'][$key] = $variables['elements'][$key];
  }
}