Skip to content

Commit cc7ee2e

Browse files
committed
Fix required validation during preview.
1 parent d0c1546 commit cc7ee2e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Plugin/views/filter/Selective.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,31 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
118118
// }
119119
}
120120

121+
/**
122+
* {@inheritdoc}
123+
*/
124+
public function validate() {
125+
$this->getValueOptions();
126+
$errors = array();
127+
128+
// If the operator is an operator which doesn't require a value, there is
129+
// no need for additional validation.
130+
if (in_array($this->operator, $this->operatorValues(0))) {
131+
return array();
132+
}
133+
134+
if (!in_array($this->operator, $this->operatorValues(1))) {
135+
$errors[] = $this->t('The operator is invalid on filter: @filter.', array('@filter' => $this->adminLabel(TRUE)));
136+
}
137+
if (is_array($this->value)) {
138+
// This is overridden because it causes problems during preview.
139+
}
140+
elseif (!empty($this->value) && ($this->operator == 'in' || $this->operator == 'not in')) {
141+
$errors[] = $this->t('The value @value is not an array for @operator on filter: @filter', array('@value' => var_export($this->value), '@operator' => $this->operator, '@filter' => $this->adminLabel(TRUE)));
142+
}
143+
return $errors;
144+
}
145+
121146
/**
122147
* Checks if two base fields are compatible.
123148
*/

0 commit comments

Comments
 (0)