public function ParagraphsTableWidget::settingsForm in Paragraphs table 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.
Overrides ParagraphsWidget::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ ParagraphsTableWidget.php, line 40
Class
- ParagraphsTableWidget
- Plugin implementation of the 'paragraphs_table_widget' widget.
Namespace
Drupal\paragraphs_table\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = [];
$elements['vertical'] = [
'#type' => 'checkbox',
'#title' => t('Table vertical'),
'#description' => t('If checked, table data will show in vertical mode.'),
'#default_value' => !empty($this
->getSetting('vertical')) ? $this
->getSetting('vertical') : FALSE,
];
$elements['paste_clipboard'] = [
'#type' => 'checkbox',
'#title' => t('Paste from clipboard'),
'#description' => t('Add multiple rows, you can paste data from Excel'),
'#default_value' => !empty($this
->getSetting('paste_clipboard')) ? $this
->getSetting('paste_clipboard') : FALSE,
];
$cardinality = $this->fieldDefinition
->get('fieldStorage')
->get('cardinality');
if ($cardinality > 1) {
$elements['show_all'] = [
'#type' => 'checkbox',
'#title' => t('Show all %cardinality items in form', [
'%cardinality' => $cardinality,
]),
'#description' => t('If checked, remove button add more.'),
'#default_value' => !empty($this
->getSetting('show_all')) ? $this
->getSetting('show_all') : FALSE,
];
}
if (!in_array($cardinality, range(0, 3))) {
$elements['features'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Enable widget features'),
'#options' => [
'duplicate' => $this
->t('Duplicate'),
],
'#default_value' => $this
->getSetting('features'),
'#multiple' => TRUE,
];
}
return $elements;
}