You are here

public function WebformSubmissionNumericFilter::valueForm in Webform Views Integration 8.5

Provide a simple textfield for equality

Overrides NumericFilter::valueForm

File

src/Plugin/views/filter/WebformSubmissionNumericFilter.php, line 63

Class

WebformSubmissionNumericFilter
Filter based on numeric value of a webform submission.

Namespace

Drupal\webform_views\Plugin\views\filter

Code

public function valueForm(&$form, FormStateInterface $form_state) {
  parent::valueForm($form, $form_state);
  $webform = $this->entityTypeManager
    ->getStorage('webform')
    ->load($this->definition['webform_id']);

  // A set of possible locations where webform element widget might have to
  // be inserted.
  $possible_locations = [];
  $possible_locations[] = [
    'value',
  ];
  $possible_locations[] = [
    'value',
    'value',
  ];
  $possible_locations[] = [
    'value',
    'min',
  ];
  $possible_locations[] = [
    'value',
    'max',
  ];
  foreach ($possible_locations as $possible_location) {
    $key_exists = FALSE;
    $element =& NestedArray::getValue($form, $possible_location, $key_exists);
    if ($key_exists && isset($element['#type']) && $element['#type'] != 'value') {
      $default_value = end($possible_location);
      $default_value = isset($this->value[$default_value]) ? $this->value[$default_value] : NULL;
      $element = [
        '#title' => $element['#title'],
        '#default_value' => $default_value,
        '#required' => FALSE,
        '#states' => $element['#states'],
      ] + $webform
        ->getElementInitialized($this->definition['webform_submission_field']);
    }
  }
}