You are here

public function AgreeTerms::buildPaneForm in Commerce Agree Terms 8

Builds the pane form.

Parameters

array $pane_form: The pane form, containing the following basic properties:

  • #parents: Identifies the position of the pane form in the overall parent form, and identifies the location where the field values are placed within $form_state->getValues().

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the parent form.

array $complete_form: The complete form structure.

Overrides CheckoutPaneInterface::buildPaneForm

File

src/Plugin/Commerce/CheckoutPane/AgreeTerms.php, line 129

Class

AgreeTerms
Provides the completion message pane.

Namespace

Drupal\commerce_agree_terms\Plugin\Commerce\CheckoutPane

Code

public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
  $prefix_text = $this->configuration['prefix_text'];
  $link_text = $this->configuration['link_text'];
  $nid = $this->configuration['nid'];
  if ($nid) {
    $node = Node::load($nid);
    $attributes = [];
    if ($this->configuration['new_window']) {
      $attributes = [
        'attributes' => [
          'target' => '_blank',
        ],
      ];
    }
    $link = Link::createFromRoute($this
      ->t($link_text), 'entity.node.canonical', [
      'node' => $nid,
    ], $attributes)
      ->toString();
    if ($prefix_text) {
      $pane_form['terms_and_conditions'] = [
        '#type' => 'checkbox',
        '#default_value' => FALSE,
        '#title' => $this
          ->t($prefix_text, [
          '%terms' => $link,
        ]),
        '#required' => TRUE,
        '#weight' => $this
          ->getWeight(),
      ];
    }
    else {
      $pane_form['terms_and_conditions'] = [
        '#type' => 'checkbox',
        '#default_value' => FALSE,
        '#title' => $link,
        '#required' => TRUE,
        '#weight' => $this
          ->getWeight(),
      ];
    }
  }
  return $pane_form;
}