You are here

public static function RulesDataUIPaymentSettings::inputForm in Commerce Core 7

Constructs the direct input form.

Return value

array The direct input form.

Overrides RulesDataDirectInputFormInterface::inputForm

File

modules/payment/commerce_payment.rules.inc, line 297
Rules integration for payments.

Class

RulesDataUIPaymentSettings
Adds a payment method settings form to the enabling action.

Code

public static function inputForm($name, $info, $settings, RulesPlugin $element) {

  // If the specified payment method exists...
  if (!empty($info['payment_method']) && ($payment_method = commerce_payment_method_load($info['payment_method']))) {
    $form[$name]['method_id'] = array(
      '#type' => 'value',
      '#value' => $info['payment_method'],
    );

    // If the payment method has a settings callback...
    if ($callback = commerce_payment_method_callback($payment_method, 'settings_form')) {

      // Prepare an array of payment method settings defaults.
      $method_settings = !empty($settings[$name]['settings']) && is_array($settings[$name]['settings']) ? $settings[$name]['settings'] : array();

      // Add the settings form elements to the action form.
      $form[$name]['settings'] = $callback($method_settings);
    }
    else {

      // Otherwise add an appropriate message.
      $form[$name]['settings']['no_settings']['#markup'] = t('No settings for this payment method.');
    }
  }
  else {
    $form[$name]['invalid']['#markup'] = t('Invalid or missing payment method.');
  }
  return $form;
}