-
Notifications
You must be signed in to change notification settings - Fork 3
/
os2forms.module
93 lines (84 loc) · 2.86 KB
/
os2forms.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
<?php
/**
* @file
* OS2Forms functionality module.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_entity_type_build().
*
* Adding os2forms_settings for to webform.
*/
function os2forms_entity_type_build(array &$entity_types) {
$entity_types['webform']->setFormClass('os2forms_settings', 'Drupal\os2forms\Form\WebformSettingsForm');
}
/**
* Implements hook_webform_third_party_settings_form_alter().
*/
function os2forms_webform_third_party_settings_form_alter(&$form, FormStateInterface $form_state) {
// OS2Forms.
$form['third_party_settings']['os2forms'] = [
'#type' => 'details',
'#title' => t('OS2Forms'),
'#open' => TRUE,
'#description' => t('OS2Forms related settings'),
];
}
/**
* Implements hook_webform_admin_third_party_settings_form_alter().
*/
function os2forms_webform_admin_third_party_settings_form_alter(&$form, FormStateInterface $form_state) {
$form['third_party_settings']['os2forms'] = [
'#type' => 'details',
'#title' => t('OS2Forms'),
];
/** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
$third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
$webform_entity_storage = \Drupal::service('entity_type.manager')->getStorage('webform');
$form['third_party_settings']['os2forms']['migrate_to_category'] = [
'#type' => 'webform_select_other',
'#title' => t('Migrate webforms to category'),
'#description' => t('After migration webforms will get this category.'),
'#options' => $webform_entity_storage->getCategories(),
'#empty_value' => '',
'#default_value' => $third_party_settings_manager->getThirdPartySetting('os2forms', 'migrate_to_category') ?: NULL,
];
}
/**
* Implements hook_theme().
*/
function os2forms_theme() {
return [
'webform_handler_save_to_file_summary' => [
'variables' => ['settings' => NULL, 'handler' => NULL],
],
];
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function os2forms_menu_local_tasks_alter(&$data, $route_name) {
$webform = \Drupal::routeMatch()->getParameter('webform');
$routeName = \Drupal::routeMatch()->getRouteName();
if ($webform && $routeName == $route_name) {
if (is_object($webform)) {
$webform = $webform->id();
}
if (isset($data['tabs'][0]['entity.webform.embed']) && !\Drupal::currentUser()->hasPermission('os2forms embed webform access')) {
unset($data['tabs'][0]['entity.webform.embed']);
}
}
}
/**
* Implements hook_module_implements_alter().
*/
function os2forms_module_implements_alter(&$implementations, $hook) {
switch ($hook) {
// Move our hook_entity_type_alter() implementation to the end of the list.
case 'menu_local_tasks_alter':
$group = $implementations['os2forms'];
unset($implementations['os2forms']);
$implementations['os2forms'] = $group;
break;
}
}