public function ViewsIfEmpty::buildOptionsForm in Views If Empty 8
Default options form that provides the label widget that all fields should have.
Overrides FieldPluginBase::buildOptionsForm
File
- src/
Plugin/ views/ field/ ViewsIfEmpty.php, line 60 - Contains \Drupal\views_ifempty\Plugin\views\field\ViewsIfEmpty.
Class
- ViewsIfEmpty
- Field handler to output an alternate field when a field is empty.
Namespace
Drupal\views_ifempty\Plugin\views\fieldCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
// Scan all the fields and add them as options for our field selectors.
$fields = array(
0 => '- ' . $this
->t('no field selected') . ' -',
);
foreach ($this->view->display_handler
->getHandlers('field') as $field => $handler) {
// We only use fields up to (not including) this one.
if ($field == $this->options['id']) {
break;
}
$fields[$field] = $handler
->adminLabel();
}
$form['emptyfield'] = array(
'#type' => 'select',
'#title' => $this
->t('If this field is empty'),
'#description' => $this
->t('Check this field to see if is empty. This field will be output normally if not empty.'),
'#options' => $fields,
'#default_value' => $this->options['emptyfield'],
);
$form['outputfield'] = array(
'#type' => 'select',
'#title' => $this
->t('Then output this field'),
'#description' => $this
->t('Only output this field when the other field is empty. This field will be hidden if the other field is not empty.'),
'#options' => $fields,
'#default_value' => $this->options['outputfield'],
);
$form['reverse'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Reverse'),
'#description' => $this
->t('Reverse the normal behavior. Show the output field if the other field is <em>not</em> empty. If the other field is empty, output nothing.'),
'#default_value' => $this->options['reverse'],
);
}