public function ParagraphsTableFormatter::settingsForm in Paragraphs table 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ ParagraphsTableFormatter.php, line 106
Class
- ParagraphsTableFormatter
- Plugin implementation of the 'paragraphs_table_formatter' formatter.
Namespace
Drupal\paragraphs_table\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$settingForm = [
'view_mode' => [
'#type' => 'select',
'#options' => $this->entityDisplayRepository
->getViewModeOptions($this
->getFieldSetting('target_type')),
'#title' => $this
->t('View mode'),
'#default_value' => $this
->getSetting('view_mode'),
'#required' => TRUE,
],
'caption' => [
'#title' => $this
->t('Caption'),
'#description' => $this
->t('Caption of table'),
'#type' => 'textfield',
'#default_value' => $this
->getSettings()['caption'],
],
'vertical' => [
'#title' => $this
->t('Table vertical'),
'#description' => $this
->t('If checked, table data will show in vertical mode'),
'#type' => 'checkbox',
'#default_value' => $this
->getSettings()['vertical'],
],
'mode' => [
'#title' => $this
->t('Table Mode'),
'#description' => $this
->t('Select the table extension.'),
'#type' => 'select',
'#default_value' => $this
->getSettings()['mode'],
'#options' => $this
->getConfigurableViewModes(),
'#empty_option' => $this
->t('Default'),
'#states' => [
'visible' => [
'input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][vertical]"]' => [
'checked' => FALSE,
],
],
],
],
'chart_type' => [
'#title' => $this
->t('Chart type'),
'#description' => '<a href="https://developers-dot-devsite-v2-prod.appspot.com/chart/interactive/docs/gallery" target="_blank">Google charts</a>',
'#type' => 'select',
'#default_value' => $this
->getSettings()['chart_type'],
'#options' => $this
->googleChartsOption(),
'#empty_option' => $this
->t('Default'),
'#states' => [
'visible' => [
'select[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][mode]"]' => [
'value' => 'googleCharts',
],
],
],
],
'chart_width' => [
'#title' => $this
->t('Chart width'),
'#type' => 'number',
'#default_value' => $this
->getSettings()['chart_width'],
'#states' => [
'visible' => [
'select[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][mode]"]' => [
'value' => 'googleCharts',
],
],
],
],
'chart_height' => [
'#title' => $this
->t('Chart height'),
'#type' => 'number',
'#default_value' => $this
->getSettings()['chart_height'],
'#states' => [
'visible' => [
'select[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][mode]"]' => [
'value' => 'googleCharts',
],
],
],
],
'empty_cell_value' => [
'#title' => $this
->t('Fill Blank Cells in table'),
'#description' => $this
->t('The string which should be displayed in empty cells. Defaults to an empty string.'),
'#type' => 'textfield',
'#default_value' => $this
->getSettings()['empty_cell_value'],
],
'empty' => [
'#title' => $this
->t('Hide empty columns'),
'#description' => $this
->t('If enabled, hide empty paragraphs table columns'),
'#type' => 'checkbox',
'#default_value' => $this
->getSettings()['empty'],
'#states' => [
'visible' => [
'input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][vertical]"]' => [
'checked' => FALSE,
],
],
],
],
'ajax' => [
'#title' => $this
->t('Load table with ajax'),
'#description' => $this
->t('User for big data, ajax will load table data'),
'#type' => 'checkbox',
'#default_value' => $this
->getSettings()['ajax'],
'#states' => [
'visible' => [
'input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][vertical]"]' => [
'checked' => FALSE,
],
],
],
],
'custom_class' => [
'#title' => $this
->t('Set table class'),
'#type' => 'textfield',
'#default_value' => $this
->getSettings()['custom_class'],
],
'hide_line_operations' => [
'#title' => $this
->t('Hide line operations'),
'#type' => 'checkbox',
'#default_value' => $this
->getSettings()['hide_line_operations'],
],
];
if (\Drupal::service('module_handler')
->moduleExists('quick_data')) {
$settingForm['import'] = [
'#title' => $this
->t('Import link title'),
'#description' => $this
->t("Leave it blank if you don't want to import csv data"),
'#type' => 'textfield',
'#default_value' => $this
->getSettings()['import'],
];
}
return $settingForm + parent::settingsForm($form, $form_state);
}