forked from goalgorilla/open_social
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocial.profile
208 lines (187 loc) · 7.81 KB
/
social.profile
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* @file
* Enables modules and site configuration for a social site installation.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_install_tasks().
*/
function social_install_tasks(&$install_state) {
$tasks = array(
'social_install_profile_modules' => array(
'display_name' => t('Install social features'),
'type' => 'batch',
),
'social_final_site_setup' => array(
),
);
return $tasks;
}
/**
* Implements hook_install_tasks_alter().
*
* Unfortunately we have to alter the verify requirements.
* This is because of https://www.drupal.org/node/1253774. The dependencies of
* dependencies are not tested. So adding requirements to our install profile
* hook_requirements will not work :(. Also take a look at install.inc function
* drupal_check_profile() it just checks for all the dependencies of our
* install profile from the info file. And no actually hook_requirements in
* there.
*/
function social_install_tasks_alter(&$tasks, $install_state) {
// Override the core install_verify_requirements task function.
$tasks['install_verify_requirements']['function'] = 'social_verify_custom_requirements';
}
/**
* install_verify_requirements callback, make sure we meet custom requirement.
*
* @param array $install_state
* The current install state.
* @return array
* All the requirements we need to meet.
*/
function social_verify_custom_requirements(&$install_state) {
// Copy pasted from install_verify_requirements().
// @todo when composer hits remove this.
// Check the installation requirements for Drupal and this profile.
$requirements = install_check_requirements($install_state);
// Verify existence of all required modules.
$requirements += drupal_verify_profile($install_state);
// Added a custom check for users to see if the Address libraries are
// downloaded.
if (!class_exists('\CommerceGuys\Addressing\Repository\AddressFormatRepository')) {
$requirements['addressing_library'] = [
'title' => t('Address module requirements)'),
'value' => t('Not installed'),
'description' => t('The Address module requires the commerceguys/addressing library. <a href=":link" target="_blank">For more information check our readme</a>', array(':link' => 'https://github.com/goalgorilla/drupal_social/blob/master/readme.md#install-from-project-page-on-drupalorg')),
'severity' => REQUIREMENT_ERROR,
];
}
if (!class_exists('\CommerceGuys\Enum\AbstractEnum')) {
$requirements['addressing_library_enum'] = [
'title' => t('Address module requirements)'),
'value' => t('Not installed'),
'description' => t('The Address module requires the commerceguys/enum library. <a href=":link" target="_blank">For more information check our readme</a>', array(':link' => 'https://github.com/goalgorilla/drupal_social/blob/master/readme.md#install-from-project-page-on-drupalorg')),
'severity' => REQUIREMENT_ERROR,
];
}
if (!class_exists('\CommerceGuys\Intl\Country\CountryRepository')) {
$requirements['addressing_library_country'] = [
'title' => t('Address module requirements)'),
'value' => t('Not installed'),
'description' => t('The Address module requires the commerceguys/intl library. <a href=":link" target="_blank">For more information check our readme</a>', array(':link' => 'https://github.com/goalgorilla/drupal_social/blob/master/readme.md#install-from-project-page-on-drupalorg')),
'severity' => REQUIREMENT_ERROR,
];
}
if (!class_exists('\CommerceGuys\Zone\Repository\ZoneRepository')) {
$requirements['addressing_library_zone'] = [
'title' => t('Address module requirements)'),
'value' => t('Not installed'),
'description' => t('The Address module requires the commerceguys/zone library. <a href=":link" target="_blank">For more information check our readme</a>', array(':link' => 'https://github.com/goalgorilla/drupal_social/blob/master/readme.md#install-from-project-page-on-drupalorg')),
'severity' => REQUIREMENT_ERROR,
];
}
// Check to see if bcmath extension is actually available.
$bc_math_enabled = (extension_loaded('bcmath'));
if (!$bc_math_enabled) {
$requirements['bcmatch'] = array(
'title' => t('BC Math'),
'value' => t('Not installed'),
'severity' => REQUIREMENT_ERROR,
'description' => t('the PHP BC Math library is not installed (correctly). <a href=":link" target="_blank">For more information check our readme</a>', array(':link' => 'https://github.com/goalgorilla/drupal_social/blob/master/readme.md#install-from-project-page-on-drupalorg')),
);
}
return install_display_requirements($install_state, $requirements);
}
/**
* Installs required modules via a batch process.
*
* @param $install_state
* An array of information about the current installation state.
*
* @return
* The batch definition.
*/
function social_install_profile_modules(&$install_state) {
$files = system_rebuild_module_data();
$modules = array(
'social_core' => 'social_core',
'social_user' => 'social_user',
'social_group' => 'social_group',
'social_event' => 'social_event',
'social_topic' => 'social_topic',
'social_profile' => 'social_profile',
'social_editor' => 'social_editor',
'social_comment' => 'social_comment',
'social_post' => 'social_post',
'social_page' => 'social_page',
'social_search' => 'social_search',
'social_activity' => 'social_activity',
);
$social_modules = $modules;
// Always install required modules first. Respect the dependencies between
// the modules.
$required = array();
$non_required = array();
// Add modules that other modules depend on.
foreach ($modules as $module) {
if ($files[$module]->requires) {
$module_requires = array_keys($files[$module]->requires);
// Remove the social modules from required modules.
$module_requires = array_diff_key($module_requires, $social_modules);
$modules = array_merge($modules, $module_requires);
}
}
$modules = array_unique($modules);
// Remove the social modules from to install modules.
$modules = array_diff_key($modules, $social_modules);
foreach ($modules as $module) {
if (!empty($files[$module]->info['required'])) {
$required[$module] = $files[$module]->sort;
}
else {
$non_required[$module] = $files[$module]->sort;
}
}
arsort($required);
$operations = array();
foreach ($required + $non_required + $social_modules as $module => $weight) {
$operations[] = array('_social_install_module_batch', array(array($module), $module));
}
$batch = array(
'operations' => $operations,
'title' => t('Installing Social features'),
'error_message' => t('The installation has encountered an error.'),
);
return $batch;
}
/**
* Implements callback_batch_operation().
*
* Performs batch installation of modules.
*/
function _social_install_module_batch($module, $module_name, &$context) {
set_time_limit(0);
\Drupal::service('module_installer')->install($module, $dependencies = TRUE);
$context['results'][] = $module;
$context['message'] = t('Installed %module_name modules.', array('%module_name' => $module_name));
}
/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
* Allows the profile to alter the site configuration form.
*/
function social_form_install_configure_form_alter(&$form, FormStateInterface $form_state) {
// Add a placeholder as example that one can choose an arbitrary site name.
$form['site_information']['site_name']['#attributes']['placeholder'] = t('Open Social');
}
/**
* @param $install_state
*/
function social_final_site_setup(&$install_state) {
// Rebuild permissions.
node_access_rebuild(); // TODO Do not set message?
// TODO node_access_needs_rebuild(FALSE) is also good because no content yet?
// TODO Enable demo and devel, generate demo content via batch?
}