function EntityReference::valueForm
Overrides ManyToOne::valueForm
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ EntityReference.php, line 406
Class
- EntityReference
- Filters a view by entity references.
Namespace
Drupal\views\Plugin\views\filterCode
protected function valueForm(&$form, FormStateInterface $form_state) {
if (!isset($this->options['sub_handler'])) {
return;
}
switch ($this->options['widget']) {
case static::WIDGET_SELECT:
$this->valueFormAddSelect($form, $form_state);
break;
case static::WIDGET_AUTOCOMPLETE:
$this->valueFormAddAutocomplete($form, $form_state);
break;
}
if (!empty($this->view->live_preview)) {
$this->alternateWidgetsDefaultNormalize($form, $form_state);
}
// Show or hide the value field depending on the operator field.
$is_exposed = $this->options['exposed'];
$visible = [];
if ($is_exposed) {
$operator_field = $this->options['expose']['use_operator'] && $this->options['expose']['operator_id'] ? $this->options['expose']['operator_id'] : NULL;
}
else {
$operator_field = 'options[operator]';
$visible[] = [
':input[name="options[expose_button][checkbox][checkbox]"]' => [
'checked' => TRUE,
],
':input[name="options[expose][use_operator]"]' => [
'checked' => TRUE,
],
':input[name="options[expose][operator_id]"]' => [
'empty' => FALSE,
],
];
}
if ($operator_field) {
foreach ($this->operatorValues(1) as $operator) {
$visible[] = [
':input[name="' . $operator_field . '"]' => [
'value' => $operator,
],
];
}
$form['value']['#states'] = [
'visible' => $visible,
];
}
if (!$is_exposed) {
// Retain the helper option.
$this->helper
->buildOptionsForm($form, $form_state);
// Show help text if not exposed to end users.
$form['value']['#description'] = $this->t('Leave blank for all. Otherwise, the first selected item will be the default instead of "Any".');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.