ConfigForm.php in PDF 8
File
src/Form/ConfigForm.php
View source
<?php
namespace Drupal\pdf\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConfigForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'pdf.settings',
];
}
public function getFormId() {
return 'config_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('pdf.settings');
$form['custom_viewer'] = [
'#type' => 'textfield',
'#title' => $this
->t('Path to custom viewer.html file'),
'#description' => $this
->t('Specify a custom viewer.html file. This should be a full path starting with a slash. If left empty, the default viewer.html file will be used.'),
'#maxlength' => 255,
'#size' => 64,
'#default_value' => $config
->get('custom_viewer'),
'#attributes' => [
'placeholder' => $this
->t('example: /sites/default/themes/yourtheme/pdfjs/viewer.html'),
],
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('pdf.settings')
->set('custom_viewer', $form_state
->getValue('custom_viewer'))
->save();
}
}