forked from esmero/ami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathami.module
132 lines (120 loc) · 4.05 KB
/
ami.module
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
128
129
130
131
132
<?php
/**
* @file
* Contains ami.module.
*/
use Drupal\Core\Language\Language;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\format_strawberryfield\Event\FormatStrawberryfieldFormAlterEvent;
use Drupal\format_strawberryfield\FormatStrawberryfieldEventType;
/**
* Implements hook_help().
*/
function ami_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.ami':
$text = file_get_contents(dirname(__FILE__) . "/README.md");
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . $text . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
}
function ami_form_metadatadisplay_entity_edit_form_alter(&$form,FormStateInterface $form_state, $form_id) {
// Add our AMI options here
$form['preview']['entity_type'] = [
'#type' => 'radios',
'#weight' => -10,
'#title' => t('Entity type'),
'#description' => t('The Entity Type you want to preview.'),
'#options' => [
'ado' => t('Archipelago Digital Objects'),
'ami' => t('AMI Sets'),
],
'#default_value' => $form_state->getValue('entity_type', NULL) ?? 'ado'
];
$form['preview']['ado_context_preview']['#states'] = [
'visible' => [
':input[name="entity_type"]' => ['value' => 'ado'],
],
];
$form['preview']['ado_amiset_preview'] = [
'#type' => 'entity_autocomplete',
'#weight' => -9,
'#title' => t('Ami Set to preview'),
'#description' => t('The AMI Set to be used to preview the data.'),
'#target_type' => 'ami_set_entity',
'#maxlength' => 1024,
'#ajax' => [
'callback' => '\Drupal\ami\Controller\AmiRowAutocompleteHandler::rowAjaxCallback',
'event' => 'autocompleteclose change',
],
'#states' => [
'visible' => [':input[name="entity_type"]' => ['value' => 'ami']],
],
];
$form['preview']['ado_amiset_row_context_preview'] = [
'#type' => 'textfield',
'#weight' => -8,
'#title' => t('Row to preview'),
'#states' => [
'visible' => [
'input[name="entity_type"]' => ['value' => 'ami'],
'input[name="ado_amiset_preview"' => ['filled' => true],
],
],
];
$ami_set = $form_state->getValue('ado_amiset_preview', NULL);
if (is_scalar($ami_set)) {
$form['preview']['ado_amiset_row_context_preview']['#autocomplete_route_name'] = 'ami.rowsbylabel.autocomplete';
$form['preview']['ado_amiset_row_context_preview']['#autocomplete_route_parameters'] = [
'ami_set_entity' => $ami_set
];
}
$form['preview']['button_preview'][
'#states'] = [
'visible' => [
'input[name="ado_context_preview"' => ['filled' => true],
'input[name="entity_type"]' => ['value' => 'ado'],
],
];
$form['preview']['button_preview_amiset'] = [
'#type' => 'button',
'#op' => 'preview',
'#weight' => -7,
'#value' => t('Show preview for AMI Set'),
'#ajax' => [
'callback' => '\Drupal\ami\Controller\AmiRowAutocompleteHandler::ajaxPreviewAmiSet',
],
'#states' => [
'visible' => [
'input[name="ado_amiset_preview"' => ['filled' => true],
'input[name="entity_type"]' => ['value' => 'ami']
],
],
];
$form['preview']['render_native'] = [
'#type' => 'checkbox',
'#weight' => 10,
'#defaut_value' => FALSE,
'#title' => 'Show Preview using native Output Format (e.g HTML)',
'#states' => [
'visible' => [
['input[name="ado_context_preview"' => ['filled' => true]],
'or',
['input[name="ado_amiset_preview"' => ['filled' => true],
'input[name="ado_amiset_row_context_preview"' => ['filled' => true]]
],
],
];
return $form;
}