You are here

public static function WebformOtherBase::valueCallback in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformOtherBase.php \Drupal\webform\Element\WebformOtherBase::valueCallback()

Determines how user input is mapped to an element's #value property.

Parameters

array $element: An associative array containing the properties of the element.

mixed $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.

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

Return value

mixed The value to assign to the element.

Overrides FormElement::valueCallback

1 call to WebformOtherBase::valueCallback()
WebformRadiosOther::valueCallback in src/Element/WebformRadiosOther.php
Determines how user input is mapped to an element's #value property.
1 method overrides WebformOtherBase::valueCallback()
WebformRadiosOther::valueCallback in src/Element/WebformRadiosOther.php
Determines how user input is mapped to an element's #value property.

File

src/Element/WebformOtherBase.php, line 88

Class

WebformOtherBase
Base class for webform other element.

Namespace

Drupal\webform\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {

  // Remove 'webform_' prefix from type.
  $type = str_replace('webform_', '', static::$type);
  if ($input === FALSE) {
    $value = static::convertDefaultValueToElementValue($element);
    $element[$type]['#default_value'] = $value[$type];
    if ($value['other'] !== NULL) {
      $element['other']['#default_value'] = $value['other'];
    }
    return $value;
  }

  // Return NULL so that current $input is used.
  return NULL;
}