You are here

public static function WebformVariant::processWebformVariant in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformVariant.php \Drupal\webform\Element\WebformVariant::processWebformVariant()

#process callback for webform variant.

Parameters

array $element: An associative array containing the properties and children of the generic input element.

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

array $complete_form: The complete form structure.

Return value

array The processed element.

File

src/Element/WebformVariant.php, line 46

Class

WebformVariant
Provides a webform variant element.

Namespace

Drupal\webform\Element

Code

public static function processWebformVariant(&$element, FormStateInterface $form_state, &$complete_form) {
  $form_object = $form_state
    ->getFormObject();
  if ($element['#value']) {
    $element['#children'] = $element['#value'];
    if ($form_object instanceof WebformSubmissionForm) {

      // Display variant label.

      /** @var \Drupal\webform\WebformInterface $webform */
      $webform = $form_object
        ->getWebform();
      if ($webform
        ->hasVariant($element['#value'])) {
        $variant_plugin = $webform
          ->getVariant($element['#value']);
        $element['#children'] = $variant_plugin
          ->label();
      }
    }
  }
  return $element;
}