public function ParagraphsJQueryUIAccordionFormatter::settingsForm in Paragraphs jQuery UI Accordion 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/ ParagraphsJQueryUIAccordionFormatter.php, line 156 - Contains \Drupal\paragraphs_jquery_ui_accordion\Plugin\Field\FieldFormatter\ParagraphsJQueryUIAccordionFormatter.
Class
- ParagraphsJQueryUIAccordionFormatter
- Plugin implementation of the 'paragraphs_jquery_ui_accordion_formatter' formatter.
Namespace
Drupal\paragraphs_jquery_ui_accordion\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$bundles = $this
->getBundles();
$bundle_fields = $this
->getBundleFields();
$form['bundle'] = [
'#type' => 'select',
'#title' => $this
->t('Paragraph bundle'),
'#default_value' => $this
->getSetting('bundle'),
'#options' => $bundles,
];
$form['title'] = [
'#type' => 'select',
'#title' => $this
->t('Paragraph title'),
'#default_value' => $this
->getSetting('title'),
'#options' => $bundle_fields,
];
$form['content'] = [
'#type' => 'select',
'#title' => $this
->t('Paragraph content'),
'#default_value' => $this
->getSetting('content'),
'#options' => $bundle_fields,
];
$form['view_mode'] = array(
'#type' => 'select',
'#options' => $this->entityDisplayRepository
->getViewModeOptions($this
->getFieldSetting('target_type')),
'#title' => $this
->t('View mode'),
'#description' => $this
->t('This view mode will be applied for content field selected above.'),
'#default_value' => $this
->getSetting('view_mode'),
'#required' => TRUE,
);
$form['active'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Active'),
'#description' => $this
->t('Makes first panel is open.'),
'#default_value' => $this
->getSetting('active'),
];
$form['simple_id'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Simple Ids'),
'#description' => $this
->t('This makes each accordion id in numerical order (#1, #2, #3 etc).<br />Note this may break functionality if you are using multiple accordions on the same page.'),
'#default_value' => $this
->getSetting('simple_id'),
];
$form['autoscroll'] = [
'#type' => 'checkbox',
'#title' => $this
->t('AutoScroll'),
'#description' => $this
->t('Scrolls to active accordion item.'),
'#default_value' => $this
->getSetting('autoscroll'),
'#attributes' => [
'setting-name' => 'autoscroll',
],
];
$form['autoscroll_offset'] = [
'#type' => 'textfield',
'#title' => $this
->t('AutoScroll offset'),
'#description' => $this
->t('Adds extra margin if such exist in your page layout (for example if enabled admin_toolbar module, then you need set 80px).<br />Leave empty if not needed.'),
'#default_value' => $this
->getSetting('autoscroll_offset'),
'#states' => [
'visible' => [
[
':input[setting-name="autoscroll"]' => [
'checked' => TRUE,
],
],
],
],
'#size' => 20,
'#field_suffix' => 'px',
];
$form['autoscroll_offset_toolbar'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Apply offset only for admin toolbar.'),
'#default_value' => $this
->getSetting('autoscroll_offset_toolbar'),
'#states' => [
'visible' => [
[
':input[setting-name="autoscroll"]' => [
'checked' => TRUE,
],
],
],
],
];
return $form;
}