You are here

public function WebformVariantApplyForm::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformVariantApplyForm.php \Drupal\webform\Form\WebformVariantApplyForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides WebformDeleteFormBase::buildForm

File

src/Form/WebformVariantApplyForm.php, line 116

Class

WebformVariantApplyForm
Form for apply a webform variant.

Namespace

Drupal\webform\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL) {
  $this->webform = $webform;
  $variant_id = $this
    ->getRequest()->query
    ->get('variant_id');
  if ($variant_id) {

    // Throw access denied exception is the variant does not exist.
    if (!$webform
      ->getVariants()
      ->has($variant_id)) {
      throw new AccessDeniedHttpException();
    }
    $this->webformVariant = $webform
      ->getVariant($variant_id);
  }
  $this->hasMultipleVariants = count($this->webform
    ->getElementsVariant()) > 1 ? TRUE : FALSE;
  return parent::buildForm($form, $form_state);
}