function String::value_form in Views (for Drupal 7) 8.3
Provide a simple textfield for equality
Overrides FilterPluginBase::value_form
File
- lib/
Drupal/ views/ Plugin/ views/ filter/ String.php, line 193 - Definition of Drupal\views\Plugin\views\filter\String.
Class
- String
- Basic textfield filter to handle string filtering commands including equality, like, not like, etc.
Namespace
Drupal\views\Plugin\views\filterCode
function value_form(&$form, &$form_state) {
// We have to make some choices when creating this as an exposed
// filter form. For example, if the operator is locked and thus
// not rendered, we can't render dependencies; instead we only
// render the form items we need.
$which = 'all';
if (!empty($form['operator'])) {
$source = ':input[name="options[operator]"]';
}
if (!empty($form_state['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
->operator_values(1)) ? 'value' : 'none';
}
else {
$source = ':input[name="' . $this->options['expose']['operator_id'] . '"]';
}
}
if ($which == 'all' || $which == 'value') {
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Value'),
'#size' => 30,
'#default_value' => $this->value,
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
}
if ($which == 'all') {
// Setup #states for all operators with one value.
foreach ($this
->operator_values(1) as $operator) {
$form['value']['#states']['visible'][] = array(
$source => array(
'value' => $operator,
),
);
}
}
}
if (!isset($form['value'])) {
// Ensure there is something in the 'value'.
$form['value'] = array(
'#type' => 'value',
'#value' => NULL,
);
}
}