-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvarbase_core.module
154 lines (133 loc) · 5.61 KB
/
varbase_core.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* @file
* Contains varbase_core.module.
*/
use Drupal\Core\Form\FormStateInterface;
use Vardot\Entity\EntityDefinitionUpdateManager;
use Vardot\Installer\ModuleInstallerFactory;
use Drupal\user\UserInterface;
// To have all varbase core general and global tokens.
include_once __DIR__ . '/varbase_core.tokens.inc';
/**
* Implements hook_FORM_ID_form_alter().
*/
function varbase_core_form_node_form_alter(&$form, FormStateInterface $form_state) {
// Override node form sidebar order.
if (isset($form['author'])) {
$form['author']['#weight'] = -6;
}
if (isset($form['field_comments'])) {
$form['field_comments']['widget'][0]['#weight'] = -5;
}
if (isset($form['path_settings'])) {
$form['path_settings']['#weight'] = -4;
}
if (isset($form['field_meta_tags'])) {
$form['field_meta_tags']['widget'][0]['#weight'] = -3;
}
if (isset($form['simple_sitemap'])) {
$form['simple_sitemap']['#weight'] = -2;
}
if (isset($form['ds_switch_view_mode'])) {
$form['ds_switch_view_mode']['#weight'] = 101;
}
}
/**
* Implements hook_form_alter().
*/
function varbase_core_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Disable the checkbox to delete referenced entity from entityqueues.
$subqueue_base_form = $form_state->getBuildInfo();
if (array_key_exists('base_form_id', $subqueue_base_form)
&& $subqueue_base_form['base_form_id'] == 'entity_subqueue_form'
&& isset($form['items']['widget']['entities'])
&& !empty($form['items']['widget']['entities'])) {
foreach ($form['items']['widget']['entities'] as &$subqueue_entity) {
if (is_array($subqueue_entity)) {
if (array_key_exists('form', $subqueue_entity) && array_key_exists('delete', $subqueue_entity['form'])) {
$subqueue_entity['form']['delete']['#access'] = FALSE;
}
}
}
}
}
/**
* Implements hook_template_preprocess_default_variables_alter().
*/
function varbase_core_template_preprocess_default_variables_alter(&$variables) {
$user_settings_config = \Drupal::config('user.settings');
$variables['user_settings_register_admin_only'] = $user_settings_config->get('register') == 'admin_only' ? 1 : 0;
}
/**
* Implements hook_modules_installed().
*/
function varbase_core_modules_installed($modules, $is_syncing) {
if (in_array('automated_cron', $modules)) {
// When the Automated Cron module is enabled, which not enabled by default.
// with development and deployments to production sites.
// But the need to have the basic extra change for the settings over
// the Automated Cron default settings.
// -------------------------------------------------
// Managed configs for the Automated Cron module.
$managed_configs = [
'automated_cron.settings',
];
ModuleInstallerFactory::importConfigsFromList('varbase_core', $managed_configs, 'config/managed/automated_cron');
// Entity updates to clear up any mismatched entity and/or field definitions
// And Fix changes were detected in the entity type and field definitions.
\Drupal::classResolver()
->getInstanceFromDefinition(EntityDefinitionUpdateManager::class)
->applyUpdates();
}
if (in_array('editoria11y', $modules)) {
// When the Editoria11y Accessibility Checker module is enabled,
// which not enabled by default.
// -------------------------------------------------
// Add permissions for default user roles.
ModuleInstallerFactory::addPermissions('varbase_core', 'config/managed/editoria11y/permissions');
// Import the default configuration recipe for Editoria11y Settings as a managed config.
$editoria11y_managed_configs = [
'editoria11y.settings',
];
ModuleInstallerFactory::importConfigsFromList('varbase_core', $editoria11y_managed_configs, 'config/managed/editoria11y/recipes');
}
if (in_array('sitewide_alert', $modules)) {
// When the Sitewide Alert module is enabled, which not enabled by default.
// with development and deployments to production sites.
// But the need to have the basic extra change for the settings over
// the Sitewide Alert default settings.
// -------------------------------------------------
// Managed configs for the Sitewide Alert module.
$managed_configs = [
'sitewide_alert.settings',
];
ModuleInstallerFactory::importConfigsFromList('varbase_core', $managed_configs, 'config/managed/sitewide_alert');
}
if (in_array('varbase_default_content', $modules)) {
// When the Varbase Default content is enabled.
// It will add number of block content
// Which only the theme block for vartheme_bs5 can be created after that step.
// -------------------------------------------------
// Managed configs for the vartheme_bs5 theme.
$managed_configs = [
'block.block.vartheme_bs5_copyright',
'block.block.vartheme_bs5_footer_logo',
];
ModuleInstallerFactory::importConfigsFromList('varbase_core', $managed_configs, 'config/managed/vartheme_bs5');
}
}
/**
* Implements hook_email_registration_name_alter().
*/
function varbase_core_email_registration_name_alter(string &$accountName, UserInterface $account) {
$varbase_general_settings = \Drupal::service('config.factory')->getEditable('varbase_core.general_settings');
$allow_custom_account_name = $varbase_general_settings->get('allow_custom_account_name');
if (!isset($allow_custom_account_name)) {
$allow_custom_account_name = TRUE;
}
$custom_account_name = $account->getAccountName();
if ($allow_custom_account_name && $custom_account_name != '') {
$accountName = email_registration_unique_username($custom_account_name, (int) $account->id());
}
}