You are here

public function PaymentRefundForm::validateConfigurationForm in Commerce Core 8.2

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormBase::validateConfigurationForm

File

modules/payment/src/PluginForm/PaymentRefundForm.php, line 32

Class

PaymentRefundForm

Namespace

Drupal\commerce_payment\PluginForm

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValue($form['#parents']);
  $amount = Price::fromArray($values['amount']);

  /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
  $payment = $this->entity;
  $balance = $payment
    ->getBalance();
  if ($amount
    ->greaterThan($balance)) {
    $form_state
      ->setError($form['amount'], $this
      ->t("Can't refund more than @amount.", [
      '@amount' => $balance
        ->__toString(),
    ]));
  }
}