You are here

public function PaymentMethodConfigurationForm::form in Payment 8.2

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Entity/PaymentMethodConfiguration/PaymentMethodConfigurationForm.php, line 71

Class

PaymentMethodConfigurationForm
Provides the payment method configuration form.

Namespace

Drupal\payment\Entity\PaymentMethodConfiguration

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\payment\Entity\PaymentMethodConfigurationInterface $payment_method_configuration */
  $payment_method_configuration = $this
    ->getEntity();
  $definition = $this->paymentMethodConfigurationManager
    ->getDefinition($payment_method_configuration
    ->getPluginId());
  $form['type'] = array(
    '#type' => 'item',
    '#title' => $this
      ->t('Type'),
    '#markup' => $definition['label'],
  );
  $form['status'] = array(
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enabled'),
    '#default_value' => $payment_method_configuration
      ->status(),
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#default_value' => $payment_method_configuration
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $payment_method_configuration
      ->id(),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#machine_name' => array(
      'source' => array(
        'label',
      ),
      'exists' => array(
        $this,
        'paymentMethodConfigurationIdExists',
      ),
    ),
    '#disabled' => !$payment_method_configuration
      ->isNew(),
  );
  $form['owner'] = array(
    '#target_type' => 'user',
    '#type' => 'entity_autocomplete',
    '#title' => $this
      ->t('Owner'),
    '#default_value' => $payment_method_configuration
      ->getOwner() ? $payment_method_configuration
      ->getOwner() : $this->currentUser,
    '#required' => TRUE,
  );
  if ($form_state
    ->has('payment_method_configuration')) {
    $payment_method_configuration_plugin = $form_state
      ->get('payment_method_configuration');
  }
  else {
    $payment_method_configuration_plugin = $this->paymentMethodConfigurationManager
      ->createInstance($payment_method_configuration
      ->getPluginId(), $payment_method_configuration
      ->getPluginConfiguration());
    $form_state
      ->set('payment_method_configuration', $payment_method_configuration_plugin);
  }
  $form['plugin_form'] = array(
    '#tree' => TRUE,
  ) + $payment_method_configuration_plugin
    ->buildConfigurationForm([], $form_state);
  return parent::form($form, $form_state);
}