uc_gc_client-8.x-1.x-dev/src/Form/MandateCancel.php

src/Form/MandateCancel.php
<?php

namespace Drupal\uc_gc_client\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;

/**
 * Provides a simple form with a buttom for cancelling a mandate.
 */
class MandateCancel extends FormBase {

  /**
   * The Ubercart order of the mandate that is being cancelled.
   *
   * @var object
   */
  protected $order;

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'uc_gc_client_mandate_cancel_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $order = NULL) {
    $this->order = $order;
    $message = $this->t('Are you sure you want to cancel the direct debit mandate? This action cannot be undone.');
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Cancel'),
      '#attributes' => ['onclick' => 'if (!confirm("' . $message . '")) {return false;}'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    uc_gc_client_mandate_cancel($this->order);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc