public function ViewsConditionalField::buildOptionsForm in Views Conditional 8
Provide the options form.
Overrides FieldPluginBase::buildOptionsForm
File
- src/
Plugin/ views/ field/ ViewsConditionalField.php, line 113
Class
- ViewsConditionalField
- Field handler to flag the node type.
Namespace
Drupal\views_conditional\Plugin\views\fieldCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['relationship']['#access'] = FALSE;
$previous = $this
->getPreviousFieldLabels();
$fields = [
'- ' . $this
->t('no field selected') . ' -',
];
foreach ($previous as $id => $label) {
$field[$id] = $label;
}
$fields += $field;
$form['if'] = [
'#type' => 'select',
'#title' => $this
->t('If this field...'),
'#options' => $fields,
'#default_value' => $this->options['if'],
];
$form['condition'] = [
'#type' => 'select',
'#title' => $this
->t('Is...'),
'#options' => $this->conditions,
'#default_value' => $this->options['condition'],
];
$form['equalto'] = [
'#type' => 'textfield',
'#title' => $this
->t('This value'),
'#description' => $this
->t('Input a value to compare the field against. Replacement variables may be used'),
'#default_value' => $this->options['equalto'],
];
$form['then'] = [
'#type' => 'textarea',
'#title' => $this
->t('Then output this...'),
'#description' => $this
->t('Input what should be output. Replacement variables may be used.'),
'#default_value' => $this->options['then'],
];
$form['then_translate'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Translate "Then" output'),
'#description' => $this
->t('Translate custom text before any replacement values are substituted.'),
'#default_value' => $this->options['then_translate'],
];
$form['or'] = [
'#type' => 'textarea',
'#title' => $this
->t('Otherwise, output this...'),
'#description' => $this
->t('Input what should be output if the above conditions do NOT evaluate to true.'),
'#default_value' => $this->options['or'],
];
$form['or_translate'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Translate "Or" output'),
'#description' => $this
->t('Translate custom text before any replacement values are substituted.'),
'#default_value' => $this->options['or_translate'],
];
$form['strip_tags'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Strip html tags from the output'),
'#default_value' => $this->options['strip_tags'],
];
$form['replacements'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => $this
->t('Replacement Variables'),
];
$form['replacements']['notice'] = [
'#markup' => 'You may use any of these replacement variables in the "equals" or the "output" text fields. If you wish to use brackets ([ or ]), replace them with %5D or %5E.',
'#prefix' => '<p>',
'#suffix' => '</p>',
];
$items = [
'DATE_UNIX => Current date / time, in UNIX timestamp format (' . $this->dateTime
->getRequestTime() . ')',
'DATE_STAMP => Current date / time, in standard format (' . $this->dateFormatter
->format($this->dateTime
->getRequestTime()) . ')',
];
$views_fields = $this->view->display_handler
->getHandlers('field');
foreach ($views_fields as $field => $handler) {
// We only use fields up to (not including) this one.
if ($field == $this->options['id']) {
break;
}
$items[] = "{{ {$field} }}";
}
$form['replacements']['variables'] = [
'#theme' => 'item_list',
'#items' => $items,
];
parent::buildOptionsForm($form, $form_state);
}