You are here

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

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

Processed other element's submitted value.

Parameters

array $element: The element.

array $value: The submitted value.

Return value

array|string An array of values or a string.

1 call to WebformOtherBase::processValue()
WebformOtherBase::validateWebformOther in src/Element/WebformOtherBase.php
Validates an other element.

File

src/Element/WebformOtherBase.php, line 278

Class

WebformOtherBase
Base class for webform other element.

Namespace

Drupal\webform\Element

Code

public static function processValue(array $element, array $value) {
  $type = static::getElementType();
  $element_value = $value[$type];
  $other_value = $value['other'];
  if (static::isMultiple($element)) {
    $return_value = array_filter($element_value);
    $return_value = array_combine($return_value, $return_value);
    if (isset($return_value[static::OTHER_OPTION])) {
      unset($return_value[static::OTHER_OPTION]);
      if ($other_value !== '') {
        $return_value += [
          $other_value => $other_value,
        ];
      }
    }
    return $return_value;
  }
  else {
    return $element_value === static::OTHER_OPTION ? $other_value : $element_value;
  }
}