You are here

public function WebformCheckboxesOther::getElementSelectorInputValue in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformCheckboxesOther.php \Drupal\webform\Plugin\WebformElement\WebformCheckboxesOther::getElementSelectorInputValue()

Get an element's (sub)input selector value.

Parameters

string $selector: CSS :input selector.

string $trigger: Trigger from #states.

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

Return value

mixed The element input's value.

Overrides Checkboxes::getElementSelectorInputValue

File

src/Plugin/WebformElement/WebformCheckboxesOther.php, line 55

Class

WebformCheckboxesOther
Provides a 'checkboxes_other' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getElementSelectorInputValue($selector, $trigger, array $element, WebformSubmissionInterface $webform_submission) {
  $input_name = WebformSubmissionConditionsValidator::getSelectorInputName($selector);
  $other_type = WebformSubmissionConditionsValidator::getInputNameAsArray($input_name, 1);
  $value = $this
    ->getRawValue($element, $webform_submission) ?: [];
  if ($other_type === 'other') {
    $other_value = array_diff($value, array_keys($element['#options']));
    return $other_value ? implode(', ', $other_value) : NULL;
  }
  else {
    $option_value = WebformSubmissionConditionsValidator::getInputNameAsArray($input_name, 2);
    if (in_array($option_value, $value, TRUE)) {
      return in_array($trigger, [
        'checked',
        'unchecked',
      ]) ? TRUE : $value;
    }
    else {
      return in_array($trigger, [
        'checked',
        'unchecked',
      ]) ? FALSE : NULL;
    }
  }
}