You are here

protected function WebformVariantAddForm::prepareWebformVariant in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Form/WebformVariantAddForm.php \Drupal\webform\Form\WebformVariantAddForm::prepareWebformVariant()
1 method overrides WebformVariantAddForm::prepareWebformVariant()
WebformVariantDuplicateForm::prepareWebformVariant in src/Form/WebformVariantDuplicateForm.php

File

src/Form/WebformVariantAddForm.php, line 64

Class

WebformVariantAddForm
Provides an add form for webform variant.

Namespace

Drupal\webform\Form

Code

protected function prepareWebformVariant($webform_variant) {

  /** @var \Drupal\webform\Plugin\WebformVariantInterface $webform_variant */
  $webform_variant = $this->webformVariantManager
    ->createInstance($webform_variant);

  // Initialize the variant an pass in the webform.
  $webform_variant
    ->setWebform($this->webform);

  // Set the initial weight so this variant comes last.
  $variants = $this->webform
    ->getVariants();
  $weight = 0;
  foreach ($variants as $variant) {
    if ($weight < $variant
      ->getWeight()) {
      $weight = $variant
        ->getWeight() + 1;
    }
  }
  $webform_variant
    ->setWeight($weight);
  return $webform_variant;
}