You are here

public function ReadmoreFormatter::settingsForm in Readmore 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/ReadmoreFormatter.php \Drupal\readmore\Plugin\Field\FieldFormatter\ReadmoreFormatter::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/ReadmoreFormatter.php, line 51
Contains \Drupal\readmore\Plugin\field\FieldFormatter\ReadmoreFormatter.

Class

ReadmoreFormatter
Plugin implementation of the 'readmore' formatter.

Namespace

Drupal\readmore\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['trim_length'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Trim link text length'),
    '#field_suffix' => $this
      ->t('characters'),
    '#default_value' => $this
      ->getSetting('trim_length'),
    '#min' => 1,
    '#description' => $this
      ->t('Leave blank to allow unlimited link text lengths.'),
  ];
  $elements['trim_on_break'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Trim on @break', [
      '@break' => '<!--break-->',
    ]),
    '#description' => $this
      ->t('If @break not found in the text then trim length used.', [
      '@break' => '<!--break-->',
    ]),
    '#default_value' => $this
      ->getSetting('trim_on_break'),
  ];
  $elements['show_readmore'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show read more'),
    '#default_value' => $this
      ->getSetting('show_readmore'),
  ];
  $elements['show_readless'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show read less'),
    '#default_value' => $this
      ->getSetting('show_readless'),
  ];
  $elements['ellipsis'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add ellipsis'),
    '#default_value' => $this
      ->getSetting('ellipsis'),
  ];
  $elements['wordsafe'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Truncate on a word boundary'),
    '#default_value' => $this
      ->getSetting('wordsafe'),
  ];
  return $elements;
}