You are here

public function PDFPreviewFormatter::settingsForm in PDFPreview 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/PdfPreviewFormatter.php \Drupal\pdfpreview\Plugin\Field\FieldFormatter\PdfPreviewFormatter::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 ImageFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/PDFPreviewFormatter.php, line 104

Class

PDFPreviewFormatter
Plugin implementation of the 'pdfpreview' formatter.

Namespace

Drupal\pdfpreview\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['show_description'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Description'),
    '#description' => $this
      ->t('Show file description beside image'),
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Yes'),
    ],
    '#default_value' => $this
      ->getSetting('show_description'),
  ];
  $form['tag'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('HTML tag'),
    '#description' => $this
      ->t('Select which kind of HTML element will be used to theme elements'),
    '#options' => [
      'span' => 'span',
      'div' => 'div',
    ],
    '#default_value' => $this
      ->getSetting('tag'),
  ];
  $form['fallback_formatter'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Fallback to default file formatter'),
    '#description' => $this
      ->t('When enabled, non-PDF files will be formatted using a default file formatter.'),
    '#default_value' => (bool) $this
      ->getSetting('fallback_formatter'),
    '#return_value' => $this->configFactory
      ->get('pdfpreview.settings')
      ->get('fallback_formatter'),
  ];
  return $form;
}