function FieldPluginBase::buildOptionsForm
Same name in other branches
- 9 core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm()
- 8.9.x core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm()
- 11.x core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm()
Default option form that provides label widget that all fields should have.
Overrides HandlerBase::buildOptionsForm
24 calls to FieldPluginBase::buildOptionsForm()
- Boolean::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Boolean.php - Default option form that provides label widget that all fields should have.
- BulkForm::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ BulkForm.php - Default option form that provides label widget that all fields should have.
- Counter::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Counter.php - Default option form that provides label widget that all fields should have.
- Custom::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Custom.php - Default option form that provides label widget that all fields should have.
- Date::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Date.php - Default option form that provides label widget that all fields should have.
25 methods override FieldPluginBase::buildOptionsForm()
- Boolean::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Boolean.php - Default option form that provides label widget that all fields should have.
- BulkForm::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ BulkForm.php - Default option form that provides label widget that all fields should have.
- ContextualLinks::buildOptionsForm in core/
modules/ contextual/ src/ Plugin/ views/ field/ ContextualLinks.php - Default option form that provides label widget that all fields should have.
- Counter::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Counter.php - Default option form that provides label widget that all fields should have.
- Custom::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Custom.php - Default option form that provides label widget that all fields should have.
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ FieldPluginBase.php, line 567
Class
- FieldPluginBase
- Base class for views fields.
Namespace
Drupal\views\Plugin\views\fieldCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$label = $this->label();
$form['custom_label'] = [
'#type' => 'checkbox',
'#title' => $this->t('Create a label'),
'#default_value' => $label !== '',
'#weight' => -103,
];
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#default_value' => $label,
'#states' => [
'visible' => [
':input[name="options[custom_label]"]' => [
'checked' => TRUE,
],
],
],
'#weight' => -102,
];
$form['element_label_colon'] = [
'#type' => 'checkbox',
'#title' => $this->t('Place a colon after the label'),
'#default_value' => $this->options['element_label_colon'],
'#states' => [
'visible' => [
':input[name="options[custom_label]"]' => [
'checked' => TRUE,
],
],
],
'#weight' => -101,
];
$form['exclude'] = [
'#type' => 'checkbox',
'#title' => $this->t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => $this->t('Enable to load this field as hidden. Often used to group fields, or to use as token in another field.'),
'#weight' => -100,
];
$form['style_settings'] = [
'#type' => 'details',
'#title' => $this->t('Style settings'),
'#weight' => 99,
];
$form['element_type_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Customize field HTML'),
'#default_value' => !empty($this->options['element_type']) || (string) $this->options['element_type'] == '0' || !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_type'] = [
'#title' => $this->t('HTML element'),
'#options' => $this->getElements(),
'#type' => 'select',
'#default_value' => $this->options['element_type'],
'#description' => $this->t('Choose the HTML element to wrap around this field, e.g. H1, H2, etc.'),
'#states' => [
'visible' => [
':input[name="options[element_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_class_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add HTML class'),
'#states' => [
'visible' => [
':input[name="options[element_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_class'] = [
'#title' => $this->t('CSS class'),
'#description' => $this->t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_class'],
'#states' => [
'visible' => [
':input[name="options[element_type_enable]"]' => [
'checked' => TRUE,
],
':input[name="options[element_class_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_label_type_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Customize label HTML'),
'#default_value' => !empty($this->options['element_label_type']) || (string) $this->options['element_label_type'] == '0' || !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_label_type'] = [
'#title' => $this->t('Label HTML element'),
'#options' => $this->getElements(),
'#type' => 'select',
'#default_value' => $this->options['element_label_type'],
'#description' => $this->t('Choose the HTML element to wrap around this label, e.g. H1, H2, etc.'),
'#states' => [
'visible' => [
':input[name="options[element_label_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_label_class_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add HTML class'),
'#states' => [
'visible' => [
':input[name="options[element_label_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_label_class'] = [
'#title' => $this->t('CSS class'),
'#description' => $this->t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_label_class'],
'#states' => [
'visible' => [
':input[name="options[element_label_type_enable]"]' => [
'checked' => TRUE,
],
':input[name="options[element_label_class_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_wrapper_type_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Customize field and label wrapper HTML'),
'#default_value' => !empty($this->options['element_wrapper_type']) || (string) $this->options['element_wrapper_type'] == '0' || !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_wrapper_type'] = [
'#title' => $this->t('Wrapper HTML element'),
'#options' => $this->getElements(),
'#type' => 'select',
'#default_value' => $this->options['element_wrapper_type'],
'#description' => $this->t('Choose the HTML element to wrap around this field and label, e.g. H1, H2, etc. This may not be used if the field and label are not rendered together, such as with a table.'),
'#states' => [
'visible' => [
':input[name="options[element_wrapper_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_wrapper_class_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add HTML class'),
'#states' => [
'visible' => [
':input[name="options[element_wrapper_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#default_value' => !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
'#fieldset' => 'style_settings',
];
$form['element_wrapper_class'] = [
'#title' => $this->t('CSS class'),
'#description' => $this->t('You may use token substitutions from the rewriting section in this class.'),
'#type' => 'textfield',
'#default_value' => $this->options['element_wrapper_class'],
'#states' => [
'visible' => [
':input[name="options[element_wrapper_class_enable]"]' => [
'checked' => TRUE,
],
':input[name="options[element_wrapper_type_enable]"]' => [
'checked' => TRUE,
],
],
],
'#fieldset' => 'style_settings',
];
$form['element_default_classes'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add default classes'),
'#default_value' => $this->options['element_default_classes'],
'#description' => $this->t('Use default Views classes to identify the field, field label and field content.'),
'#fieldset' => 'style_settings',
];
$form['alter'] = [
'#title' => $this->t('Rewrite results'),
'#type' => 'details',
'#weight' => 100,
];
if ($this->allowAdvancedRender()) {
$form['alter']['#tree'] = TRUE;
$form['alter']['alter_text'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override the output of this field with custom text'),
'#default_value' => $this->options['alter']['alter_text'],
];
$form['alter']['text'] = [
'#title' => $this->t('Text'),
'#type' => 'textarea',
'#default_value' => $this->options['alter']['text'],
// The tag list will be escaped.
'#description' => $this->t('The text to display for this field. You may enter data from this view as per the "Replacement patterns" below. You may include <a href="@twig_docs">Twig</a> or the following allowed HTML tags: <code>@tags</code>', [
'@twig_docs' => 'https://twig.symfony.com/doc/' . Environment::MAJOR_VERSION . '.x',
'@tags' => '<' . implode('> <', Xss::getAdminTagList()) . '>',
]),
'#states' => [
'visible' => [
':input[name="options[alter][alter_text]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['make_link'] = [
'#type' => 'checkbox',
'#title' => $this->t('Output this field as a custom link'),
'#default_value' => $this->options['alter']['make_link'],
];
$form['alter']['path'] = [
'#title' => $this->t('Link path'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['path'],
'#description' => $this->t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
'#maxlength' => 255,
];
$form['alter']['absolute'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use absolute path'),
'#default_value' => $this->options['alter']['absolute'],
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['replace_spaces'] = [
'#type' => 'checkbox',
'#title' => $this->t('Replace spaces with dashes'),
'#default_value' => $this->options['alter']['replace_spaces'],
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['external'] = [
'#type' => 'checkbox',
'#title' => $this->t('External server URL'),
'#default_value' => $this->options['alter']['external'],
'#description' => $this->t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['path_case'] = [
'#type' => 'select',
'#title' => $this->t('Transform the case'),
'#description' => $this->t('When printing URL paths, how to transform the case of the filter value.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
'#options' => [
'none' => $this->t('No transform'),
'upper' => $this->t('Upper case'),
'lower' => $this->t('Lower case'),
'ucfirst' => $this->t('Capitalize first letter'),
'ucwords' => $this->t('Capitalize each word'),
],
'#default_value' => $this->options['alter']['path_case'],
];
$form['alter']['link_class'] = [
'#title' => $this->t('Link class'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['link_class'],
'#description' => $this->t('The CSS class to apply to the link.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['alt'] = [
'#title' => $this->t('Title text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['alt'],
'#description' => $this->t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['rel'] = [
'#title' => $this->t('Rel Text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['rel'],
'#description' => $this->t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['prefix'] = [
'#title' => $this->t('Prefix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['prefix'],
'#description' => $this->t('Any text to display before this link. You may include HTML.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['suffix'] = [
'#title' => $this->t('Suffix text'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['suffix'],
'#description' => $this->t('Any text to display after this link. You may include HTML.'),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['target'] = [
'#title' => $this->t('Target'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['target'],
'#description' => $this->t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),
'#states' => [
'visible' => [
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
],
];
// Get a list of the available fields and arguments for token replacement.
// Setup the tokens for fields.
$previous = $this->getPreviousFieldLabels();
$optgroup_arguments = (string) $this->t('Arguments');
$optgroup_fields = (string) $this->t('Fields');
foreach ($previous as $id => $label) {
$options[$optgroup_fields]["{{ {$id} }}"] = substr(strrchr($label, ":"), 2);
}
// Add the field to the list of options.
$options[$optgroup_fields]["{{ {$this->options['id']} }}"] = substr(strrchr($this->adminLabel(), ":"), 2);
foreach ($this->view->display_handler
->getHandlers('argument') as $arg => $handler) {
$options[$optgroup_arguments]["{{ arguments.{$arg} }}"] = $this->t('@argument title', [
'@argument' => $handler->adminLabel(),
]);
$options[$optgroup_arguments]["{{ raw_arguments.{$arg} }}"] = $this->t('@argument input', [
'@argument' => $handler->adminLabel(),
]);
}
$this->documentSelfTokens($options[$optgroup_fields]);
// Default text.
$output = [];
$output[] = [
'#markup' => '<p>' . $this->t('You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.') . '</p>',
];
// We have some options, so make a list.
if (!empty($options)) {
$output[] = [
'#markup' => '<p>' . $this->t("The following replacement tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.") . '</p>',
];
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = [];
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$item_list = [
'#theme' => 'item_list',
'#items' => $items,
];
$output[] = $item_list;
}
}
}
// This construct uses 'hidden' and not markup because process doesn't
// run. It also has an extra div because the dependency wants to hide
// the parent in situations like this, so we need a second div to
// make this work.
$form['alter']['help'] = [
'#type' => 'details',
'#title' => $this->t('Replacement patterns'),
'#value' => $output,
'#states' => [
'visible' => [
[
':input[name="options[alter][make_link]"]' => [
'checked' => TRUE,
],
],
[
':input[name="options[alter][alter_text]"]' => [
'checked' => TRUE,
],
],
[
':input[name="options[alter][more_link]"]' => [
'checked' => TRUE,
],
],
],
],
];
$form['alter']['trim'] = [
'#type' => 'checkbox',
'#title' => $this->t('Trim this field to a maximum number of characters'),
'#default_value' => $this->options['alter']['trim'],
];
$form['alter']['max_length'] = [
'#title' => $this->t('Maximum number of characters'),
'#type' => 'textfield',
'#default_value' => $this->options['alter']['max_length'],
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['word_boundary'] = [
'#type' => 'checkbox',
'#title' => $this->t('Trim only on a word boundary'),
'#description' => $this->t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
'#default_value' => $this->options['alter']['word_boundary'],
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['ellipsis'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add "…" at the end of trimmed text'),
'#default_value' => $this->options['alter']['ellipsis'],
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['more_link'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add a read-more link if output is trimmed'),
'#default_value' => $this->options['alter']['more_link'],
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['more_link_text'] = [
'#type' => 'textfield',
'#title' => $this->t('More link label'),
'#default_value' => $this->options['alter']['more_link_text'],
'#description' => $this->t('You may use the "Replacement patterns" above.'),
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
':input[name="options[alter][more_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['more_link_path'] = [
'#type' => 'textfield',
'#title' => $this->t('More link path'),
'#default_value' => $this->options['alter']['more_link_path'],
'#description' => $this->t('This can be an internal Drupal path such as node/add or an external URL such as "https://www.drupal.org". You may use the "Replacement patterns" above.'),
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
':input[name="options[alter][more_link]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['html'] = [
'#type' => 'checkbox',
'#title' => $this->t('Field can contain HTML'),
'#description' => $this->t('An HTML corrector will be run to ensure HTML tags are properly closed after trimming.'),
'#default_value' => $this->options['alter']['html'],
'#states' => [
'visible' => [
':input[name="options[alter][trim]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['strip_tags'] = [
'#type' => 'checkbox',
'#title' => $this->t('Strip HTML tags'),
'#default_value' => $this->options['alter']['strip_tags'],
];
$form['alter']['preserve_tags'] = [
'#type' => 'textfield',
'#title' => $this->t('Preserve certain tags'),
'#description' => $this->t('List the tags that need to be preserved during the stripping process. example "<p> <br>" which will preserve all p and br elements'),
'#default_value' => $this->options['alter']['preserve_tags'],
'#states' => [
'visible' => [
':input[name="options[alter][strip_tags]"]' => [
'checked' => TRUE,
],
],
],
];
$form['alter']['trim_whitespace'] = [
'#type' => 'checkbox',
'#title' => $this->t('Remove whitespace'),
'#default_value' => $this->options['alter']['trim_whitespace'],
];
$form['alter']['nl2br'] = [
'#type' => 'checkbox',
'#title' => $this->t('Convert newlines to HTML <br> tags'),
'#default_value' => $this->options['alter']['nl2br'],
];
}
$form['empty_field_behavior'] = [
'#type' => 'details',
'#title' => $this->t('No results behavior'),
'#weight' => 100,
];
$form['empty'] = [
'#type' => 'textarea',
'#title' => $this->t('No results text'),
'#default_value' => $this->options['empty'],
'#description' => $this->t('Provide text to display if this field contains an empty result. You may include HTML. You may enter data from this view as per the "Replacement patterns" in the "Rewrite Results" section above.'),
'#fieldset' => 'empty_field_behavior',
];
$form['empty_zero'] = [
'#type' => 'checkbox',
'#title' => $this->t('Count the number 0 as empty'),
'#default_value' => $this->options['empty_zero'],
'#description' => $this->t('Enable to display the "no results text" if the field contains the number 0.'),
'#fieldset' => 'empty_field_behavior',
];
$form['hide_empty'] = [
'#type' => 'checkbox',
'#title' => $this->t('Hide if empty'),
'#default_value' => $this->options['hide_empty'],
'#description' => $this->t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the "Hide rewriting if empty" checkbox.'),
'#fieldset' => 'empty_field_behavior',
];
$form['hide_alter_empty'] = [
'#type' => 'checkbox',
'#title' => $this->t('Hide rewriting if empty'),
'#default_value' => $this->options['hide_alter_empty'],
'#description' => $this->t('Do not display rewritten content if this field is empty.'),
'#fieldset' => 'empty_field_behavior',
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.