You are here

public function FaqFieldAccordionFormatter::settingsForm in FAQ Field 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/FaqFieldAccordionFormatter.php \Drupal\faqfield\Plugin\Field\FieldFormatter\FaqFieldAccordionFormatter::settingsForm()

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/FaqFieldAccordionFormatter.php, line 41

Class

FaqFieldAccordionFormatter
Plugin implementation of the 'faqfield_accordion' formatter.

Namespace

Drupal\faqfield\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);

  // Number of first active element.
  $elements['active'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Default active'),
    '#placeholder' => $this
      ->t('None'),
    '#default_value' => $this
      ->getSetting('active'),
    '#description' => $this
      ->t('Index of the active question starting from 0. If left empty and <em>Fully collapsible</em> is on, no question will be opened by default.'),
    '#maxlength' => 3,
    '#size' => 5,
  ];

  // Whether auto heigth is enabled.
  $elements['heightStyle'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Height style'),
    '#default_value' => $this
      ->getSetting('heightStyle'),
    '#options' => [
      'auto' => $this
        ->t('Auto : All panels will be set to the height of the tallest question.'),
      'fill' => $this
        ->t('Fill : Expand to the available height based on the accordions question height.'),
      'content' => $this
        ->t('Content : Each panel will be only as tall as its question.'),
    ],
    '#description' => $this
      ->t('Controls the height of the accordion and each panel.'),
  ];

  // Whether elements are collabsible.
  $elements['collapsible'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Fully collapsible'),
    '#default_value' => $this
      ->getSetting('collapsible'),
    '#description' => $this
      ->t('Whether all the questions can be closed at once. Allows collapsing the active section.'),
  ];

  // Name of triggering event.
  $elements['event'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Event'),
    '#placeholder' => 'click',
    '#default_value' => $this
      ->getSetting('event'),
    '#description' => $this
      ->t('The event on which to open a question. Multiple events can be specified, separated by a space.'),
  ];

  // Animation options for the accordion formatter.
  $elements['animate'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Animation settings'),
    '#collapsed' => TRUE,
  ];

  // Animation duration in milliseconds with the selected easing.
  $elements['animate']['duration'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Duration'),
    '#default_value' => $this
      ->getSetting('animate')['duration'],
    '#description' => $this
      ->t('Animation duration in milliseconds with the selected easing.'),
    '#min' => 0,
  ];

  // Name of easing to use when the event is triggered.
  $elements['animate']['easing'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Easing'),
    '#placeholder' => 'linear',
    '#default_value' => $this
      ->getSetting('animate')['easing'],
    '#description' => $this
      ->t('Name of <a href="@link">easing</a> to use when the event is triggered.', [
      '@link' => 'http://api.jqueryui.com/easings/',
    ]),
  ];
  return $elements;
}