You are here

public function FieldPdfReaderField::settingsForm in PDF Reader 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/FieldPdfReaderField.php, line 77

Class

FieldPdfReaderField
Plugin implementation of the 'FieldPdfReaderFields' formatter.

Namespace

Drupal\pdf_reader\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element['pdf_width'] = [
    '#title' => $this
      ->t('Width'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('pdf_width'),
  ];
  $element['pdf_height'] = [
    '#title' => $this
      ->t('Height'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('pdf_height'),
  ];
  $element['renderer'] = [
    '#title' => $this
      ->t('Renderer'),
    '#type' => 'select',
    '#options' => $this
      ->getPdfDisplayOptions(),
    '#default_value' => $this
      ->getSetting('renderer'),
  ];
  $element['embed_view_fit'] = [
    '#title' => $this
      ->t('Direct Embed fit option'),
    '#description' => $this
      ->t('Only applies for Direct Embed renderer'),
    '#type' => 'select',
    // See https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
    '#options' => [
      'Fit' => $this
        ->t('Fit'),
      'FitH' => $this
        ->t('Fit horizontally'),
      'FitV' => $this
        ->t('Fit vertically'),
    ],
    '#default_value' => $this
      ->getSetting('embed_view_fit'),
  ];
  $element['embed_hide_toolbar'] = [
    '#title' => $this
      ->t('Direct Embed Hide toolbar'),
    '#description' => $this
      ->t('Only applies for Direct Embed renderer'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('embed_hide_toolbar'),
  ];
  $element['download'] = [
    '#title' => $this
      ->t('Show download link'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('download'),
  ];
  $element['link_placement'] = [
    '#title' => $this
      ->t('Show Link'),
    '#type' => 'select',
    '#options' => [
      'top' => $this
        ->t('Top'),
      'bottom' => $this
        ->t('Bottom'),
    ],
    '#default_value' => $this
      ->getSetting('link_placement'),
    '#states' => [
      'invisible' => [
        'input[name="fields[field_file_to_test_ha][settings_edit_form][settings][download]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  return $element;
}