diff --git a/commerce_giftcard.module b/commerce_giftcard.module index 3e0dc2f..4c42ec7 100644 --- a/commerce_giftcard.module +++ b/commerce_giftcard.module @@ -37,3 +37,14 @@ function commerce_giftcard_entity_base_field_info(EntityTypeInterface $entity_ty } } +/** + * Implements hook_theme(). + */ +function commerce_giftcard_theme() { + return [ + 'commerce_giftcard_redemption_form' => [ + 'render element' => 'form', + ], + ]; +} + diff --git a/src/Plugin/Commerce/InlineForm/GiftcardRedemption.php b/src/Plugin/Commerce/InlineForm/GiftcardRedemption.php index bdd8234..c65164b 100644 --- a/src/Plugin/Commerce/InlineForm/GiftcardRedemption.php +++ b/src/Plugin/Commerce/InlineForm/GiftcardRedemption.php @@ -102,7 +102,7 @@ class GiftcardRedemption extends InlineFormBase { ] + $inline_form; $inline_form['code'] = [ '#type' => 'textfield', - '#title' => $this->t('Giftcard code'), + '#title' => $this->t('Gift card code'), // Chrome autofills this field with the address line 1, and ignores // autocomplete => 'off', but respects 'new-password'. '#attributes' => [ @@ -111,7 +111,7 @@ class GiftcardRedemption extends InlineFormBase { ]; $inline_form['apply'] = [ '#type' => 'submit', - '#value' => t('Apply gift card'), + '#value' => t('Redeem gift card'), '#name' => 'apply_giftcard', '#limit_validation_errors' => [ $inline_form['#parents'], @@ -135,9 +135,16 @@ class GiftcardRedemption extends InlineFormBase { $inline_form['giftcards'][$index]['code'] = [ '#plain_text' => $giftcard->getCode(), ]; + $inline_form['giftcards'][$index]['balance'] = [ + '#type' => 'inline_template', + '#template' => '{{ price|commerce_price_format }}', + '#context' => [ + 'price' => $giftcard->getBalance(), + ], + ]; $inline_form['giftcards'][$index]['remove_button'] = [ '#type' => 'submit', - '#value' => t('Remove gift card'), + '#value' => t('Remove'), '#name' => 'remove_giftcard_' . $index, '#ajax' => [ 'callback' => [get_called_class(), 'ajaxRefreshForm'], diff --git a/templates/commerce-giftcard-redemption-form.html.twig b/templates/commerce-giftcard-redemption-form.html.twig new file mode 100644 index 0000000..70e851b --- /dev/null +++ b/templates/commerce-giftcard-redemption-form.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * Template for the giftcard redemption form. + * + * Available variables: + * - form: The form. Contains the currently applied giftcards in form.giftcards, + * each containing a code and a remove_button. + * For example: form.giftcards.0.code. + * + * @ingroup themeable + */ +#} +{{ form|without('giftcards') }} + +{% if form.giftcards|length %} +