protected function InOperator::valueForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Plugin/views/filter/InOperator.php \Drupal\views\Plugin\views\filter\InOperator::valueForm()
Options form subform for setting options.
This should be overridden by all child classes and it must define $form['value']
Overrides FilterPluginBase::valueForm
See also
buildOptionsForm()
1 call to InOperator::valueForm()
- ManyToOne::valueForm in core/
modules/ views/ src/ Plugin/ views/ filter/ ManyToOne.php - Options form subform for setting options.
2 methods override InOperator::valueForm()
- ManyToOne::valueForm in core/
modules/ views/ src/ Plugin/ views/ filter/ ManyToOne.php - Options form subform for setting options.
- Name::valueForm in core/
modules/ user/ src/ Plugin/ views/ filter/ Name.php - Options form subform for setting options.
File
- core/
modules/ views/ src/ Plugin/ views/ filter/ InOperator.php, line 176 - Contains \Drupal\views\Plugin\views\filter\InOperator.
Class
- InOperator
- Simple filter to handle matching of multiple options selectable via checkboxes
Namespace
Drupal\views\Plugin\views\filterCode
protected function valueForm(&$form, FormStateInterface $form_state) {
$form['value'] = array();
$options = array();
$exposed = $form_state
->get('exposed');
if (!$exposed) {
// Add a select all option to the value form.
$options = array(
'all' => $this
->t('Select all'),
);
}
$this
->getValueOptions();
$options += $this->valueOptions;
$default_value = (array) $this->value;
$which = 'all';
if (!empty($form['operator'])) {
$source = ':input[name="options[operator]"]';
}
if ($exposed) {
$identifier = $this->options['expose']['identifier'];
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
// exposed and locked.
$which = in_array($this->operator, $this
->operatorValues(1)) ? 'value' : 'none';
}
else {
$source = ':input[name="' . $this->options['expose']['operator_id'] . '"]';
}
if (!empty($this->options['expose']['reduce'])) {
$options = $this
->reduceValueOptions();
if (!empty($this->options['expose']['multiple']) && empty($this->options['expose']['required'])) {
$default_value = array();
}
}
if (empty($this->options['expose']['multiple'])) {
if (empty($this->options['expose']['required']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
$default_value = 'All';
}
elseif (empty($default_value)) {
$keys = array_keys($options);
$default_value = array_shift($keys);
}
else {
$copy = $default_value;
$default_value = array_shift($copy);
}
}
}
if ($which == 'all' || $which == 'value') {
$form['value'] = array(
'#type' => $this->valueFormType,
'#title' => $this->valueTitle,
'#options' => $options,
'#default_value' => $default_value,
// These are only valid for 'select' type, but do no harm to checkboxes.
'#multiple' => TRUE,
'#size' => count($options) > 8 ? 8 : count($options),
);
$user_input = $form_state
->getUserInput();
if ($exposed && !isset($user_input[$identifier])) {
$user_input[$identifier] = $default_value;
$form_state
->setUserInput($user_input);
}
if ($which == 'all') {
if (!$exposed && in_array($this->valueFormType, [
'checkbox',
'checkboxes',
'radios',
'select',
])) {
$form['value']['#prefix'] = '<div id="edit-options-value-wrapper">';
$form['value']['#suffix'] = '</div>';
}
// Setup #states for all operators with one value.
foreach ($this
->operatorValues(1) as $operator) {
$form['value']['#states']['visible'][] = array(
$source => array(
'value' => $operator,
),
);
}
}
}
}