public function PdfDefault::settingsForm in PDF 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/ PdfDefault.php, line 38
Class
- PdfDefault
- Plugin annotation @FieldFormatter( id = "pdf_default", label = @Translation("PDF: Default viewer of PDF.js"), description = @Translation("Use the default viewer like http://mozilla.github.io/pdf.js/web/viewer.html."), field_types = {"file"} )
Namespace
Drupal\pdf\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$field_name = $this->fieldDefinition
->getName();
$elements['keep_pdfjs'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Always use pdf.js'),
'#default_value' => $this
->getSetting('keep_pdfjs'),
'#description' => t("Use pdf.js even when the browser has Adobe Reader Plugin, WebKit PDF Reader for Safari or the PDF Reader for Chrome (Chrome's default alternative to the Adobe Reader Plugin) installed."),
];
$elements['width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Width'),
'#default_value' => $this
->getSetting('width'),
'#description' => $this
->t('Width of the viewer. Ex: 250px or 100%'),
];
$elements['height'] = [
'#type' => 'textfield',
'#title' => $this
->t('Height'),
'#default_value' => $this
->getSetting('height'),
'#description' => $this
->t('Height of the viewer. Ex: 250px or 100%'),
];
// Extra Options.
$elements['page'] = [
'#type' => 'number',
'#title' => $this
->t('Initial page'),
'#default_value' => $this
->getSetting('page'),
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][keep_pdfjs]"]' => [
'checked' => TRUE,
],
],
],
];
$elements['zoom'] = [
'#type' => 'select',
'#title' => $this
->t('Zoom Level'),
'#default_value' => $this
->getSetting('zoom'),
'#options' => [
'' => $this
->t('- None -'),
'auto' => $this
->t('Automatic Zoom'),
'page-actual' => $this
->t('Actual Size'),
'page-fit' => $this
->t('Fit Page'),
'page-width' => $this
->t('Full Width'),
'custom' => $this
->t('Custom Scale'),
],
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][keep_pdfjs]"]' => [
'checked' => TRUE,
],
],
],
];
$elements['custom_zoom'] = [
'#type' => 'number',
'#title' => $this
->t('Custom Zoom Level (%)'),
'#default_value' => $this
->getSetting('custom_zoom'),
'#min' => 5,
'#step' => 1,
'#states' => [
'visible' => [
'select[name="fields[' . $field_name . '][settings_edit_form][settings][zoom]"]' => [
'value' => 'custom',
],
],
'required' => [
'select[name="fields[' . $field_name . '][settings_edit_form][settings][zoom]"]' => [
'value' => 'custom',
],
],
],
];
$elements['pagemode'] = [
'#type' => 'select',
'#group' => 'extra_options',
'#title' => $this
->t('Page Mode'),
'#default_value' => $this
->getSetting('pagemode'),
'#options' => [
'' => $this
->t('- None -'),
'thumbs' => $this
->t('Thumbnails'),
'bookmarks' => $this
->t('Bookmarks'),
],
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][settings_edit_form][settings][keep_pdfjs]"]' => [
'checked' => TRUE,
],
],
],
];
return $elements;
}