You are here

public function TextWithExpandCollapseButtonsFormatter::settingsForm in Formatter Suite 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/TextWithExpandCollapseButtonsFormatter.php, line 132

Class

TextWithExpandCollapseButtonsFormatter
Formats text with expand/collapse buttons to show more/less.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $formState) {

  //
  // Start with the parent form.
  $elements = parent::settingsForm($form, $formState);
  $elements['#attached'] = [
    'library' => [
      'formatter_suite/formatter_suite.settings',
    ],
  ];

  // Add branding.
  $elements = [];
  $elements = Branding::addFieldFormatterBranding($elements);
  $elements['#attached']['library'][] = 'formatter_suite/formatter_suite.fieldformatter';
  $elements['description'] = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $this
      ->getDescription(),
    '#weight' => -1000,
    '#attributes' => [
      'class' => [
        'formatter_suite-settings-description',
      ],
    ],
  ];

  // Add each of the values.
  $elements['collapsedHeight'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Collapsed height'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('collapsedHeight'),
    '#description' => $this
      ->t("Text height when collapsed. Use CSS units (e.g. '200px', '40pt', '8em'). Empty or zero value disables."),
    '#attributes' => [
      'autocomplete' => 'off',
      'autocapitalize' => 'none',
      'spellcheck' => 'false',
      'autocorrect' => 'off',
    ],
  ];
  $elements['collapseButtonLabel'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Collapse link label'),
    '#size' => 10,
    '#maxlength' => 128,
    '#default_value' => $this
      ->getSetting('collapseButtonLabel'),
  ];
  $elements['expandButtonLabel'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Expand link label'),
    '#size' => 10,
    '#maxlength' => 128,
    '#default_value' => $this
      ->getSetting('expandButtonLabel'),
  ];
  $elements['animationDuration'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Animation duration'),
    '#size' => 10,
    '#default_value' => $this
      ->getSetting('animationDuration'),
    '#description' => $this
      ->t('Animation time in milliseconds (e.g. 500 = 1/2 second). Empty or zero value disables animation.'),
  ];
  return $elements;
}