You are here

class PaymentLineItemElement in Payment 8.2

Hierarchy

Expanded class hierarchy of PaymentLineItemElement

1 string reference to 'PaymentLineItemElement'
payment_test.routing.yml in modules/payment_test/payment_test.routing.yml
modules/payment_test/payment_test.routing.yml

File

modules/payment_test/src/PaymentLineItemElement.php, line 12

Namespace

Drupal\payment_test
View source
class PaymentLineItemElement implements ContainerInjectionInterface, FormInterface {

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static();
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    // Nest the element to make sure that works.
    $form['container']['line_item'] = array(
      '#cardinality' => 4,
      '#default_value' => Generate::createPaymentLineItems(),
      '#type' => 'payment_line_items_input',
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $line_items_data = [];

    /** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface $line_item */
    foreach (PaymentLineItemsInput::getLineItems($form['container']['line_item'], $form_state) as $line_item) {
      $line_items_data[] = array(
        'plugin_id' => $line_item
          ->getPluginId(),
        'plugin_configuration' => $line_item
          ->getConfiguration(),
      );
    }
    \Drupal::state()
      ->set('payment_test_line_item_form_element', $line_items_data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentLineItemElement::buildForm public function Form constructor. Overrides FormInterface::buildForm
PaymentLineItemElement::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
PaymentLineItemElement::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
PaymentLineItemElement::submitForm public function Form submission handler. Overrides FormInterface::submitForm
PaymentLineItemElement::validateForm public function Form validation handler. Overrides FormInterface::validateForm