-
Notifications
You must be signed in to change notification settings - Fork 9
/
MiradorConfigForm.php
127 lines (114 loc) · 4.38 KB
/
MiradorConfigForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace Drupal\islandora_mirador\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora_mirador\Annotation\IslandoraMiradorPlugin;
use Drupal\islandora_mirador\IslandoraMiradorPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Mirador Settings Form.
*/
class MiradorConfigForm extends ConfigFormBase {
/**
* @var \Drupal\islandora_mirador\IslandoraMiradorPluginManager
*/
protected $miradorPluginManager;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'islandora_mirador.miradorconfig.form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this->config('islandora_mirador.settings');
$form['mirador_library_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Mirador library location'),
];
$form['mirador_library_fieldset']['mirador_library_installation_type'] = [
'#type' => 'radios',
'#options' => [
'local'=> $this->t('Local library placed in /libraries inside your webroot.'),
'remote' => $this->t('Default remote location'),
],
'#description' => $this->t("For local, put the output of 'npm run webpack' of <a href=\"https://github.com/roblib/mirador-integration-islandora\">Mirador Integration Islandora</a> into web/library/mirador/dist/ and ensure it's named main.js."),
'#default_value' => $config->get('mirador_library_installation_type'),
];
$plugins = [];
foreach ($this->miradorPluginManager->getDefinitions() as $plugin_key => $plugin_definition) {
$plugins[$plugin_key] = $plugin_definition['label'];
}
$form['mirador_library_fieldset']['mirador_enabled_plugins'] = [
'#title' => $this->t('Enabled Plugins'),
'#description' => $this->t('Which plugins to enable. The plugins must be compiled in to the application. See the documentation for instructions.'),
'#type' => 'checkboxes',
'#options' => $plugins,
'#default_value' => $config->get('mirador_enabled_plugins'),
];
$form['iiif_manifest_url_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('IIIF Manifest URL'),
];
$form['iiif_manifest_url_fieldset']['iiif_manifest_url'] = [
'#type' => 'textfield',
'#description' => $this->t('Absolute URL of the IIIF manifest to render. You may use tokens to provide a pattern (e.g. "[node:url:unaliased:absolute]/manifest" or "http://localhost/node/[node:nid]/manifest")'),
'#default_value' => $config->get('iiif_manifest_url'),
'#maxlength' => 256,
'#size' => 64,
'#required' => TRUE,
'#element_validate' => ['token_element_validate'],
'#token_types' => ['node'],
];
$form['iiif_manifest_url_fieldset']['token_help'] = [
'#theme' => 'token_tree_link',
'#global_types' => FALSE,
'#token_types' => ['node'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('islandora_mirador.settings');
$config->set('mirador_library_installation_type', $form_state->getValue('mirador_library_installation_type'));
$config->set('mirador_enabled_plugins', $form_state->getValue('mirador_enabled_plugins'));
$config->set('iiif_manifest_url', $form_state->getValue('iiif_manifest_url'));
$config->save();
parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'islandora_mirador.settings',
];
}
/**
* Constructs the Mirador config form.
*
* @param ConfigFactoryInterface $config_factory
* The configuration factory.
* @param IslandoraMiradorPluginManager $mirador_plugin_manager
* The Mirador Plugin Manager interface.
*/
public function __construct(ConfigFactoryInterface $config_factory, IslandoraMiradorPluginManager $mirador_plugin_manager) {
parent::__construct($config_factory);
$this->miradorPluginManager = $mirador_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.islandora_mirador')
);
}
}