Mercurial > hg > isophonics-drupal-site
comparison core/modules/workspaces/workspaces.install @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Contains install, update and uninstall functions for the Workspaces module. | |
6 */ | |
7 | |
8 use Drupal\workspaces\Entity\Workspace; | |
9 | |
10 /** | |
11 * Implements hook_requirements(). | |
12 */ | |
13 function workspaces_requirements($phase) { | |
14 $requirements = []; | |
15 if ($phase === 'install') { | |
16 if (\Drupal::moduleHandler()->moduleExists('content_moderation')) { | |
17 $requirements['content_moderation_incompatibility'] = [ | |
18 'severity' => REQUIREMENT_ERROR, | |
19 'description' => t('Workspaces can not be installed when Content Moderation is also installed.'), | |
20 ]; | |
21 } | |
22 if (\Drupal::moduleHandler()->moduleExists('workspace')) { | |
23 $requirements['workspace_incompatibility'] = [ | |
24 'severity' => REQUIREMENT_ERROR, | |
25 'description' => t('Workspaces can not be installed when the contributed Workspace module is also installed. See the <a href=":link">upgrade path</a> page for more information on how to upgrade.', [ | |
26 ':link' => 'https://www.drupal.org/node/2987783', | |
27 ]), | |
28 ]; | |
29 } | |
30 } | |
31 | |
32 return $requirements; | |
33 } | |
34 | |
35 /** | |
36 * Implements hook_install(). | |
37 */ | |
38 function workspaces_install() { | |
39 // Set the owner of these default workspaces to be first user which which has | |
40 // the 'administrator' role. This way we avoid hard coding user ID 1 for sites | |
41 // that prefer to not give it any special meaning. | |
42 $admin_roles = \Drupal::entityTypeManager()->getStorage('user_role')->getQuery() | |
43 ->condition('is_admin', TRUE) | |
44 ->execute(); | |
45 if (!empty($admin_roles)) { | |
46 $query = \Drupal::entityTypeManager()->getStorage('user')->getQuery() | |
47 ->condition('roles', $admin_roles, 'IN') | |
48 ->condition('status', 1) | |
49 ->sort('uid', 'ASC') | |
50 ->range(0, 1); | |
51 $result = $query->execute(); | |
52 } | |
53 | |
54 // Default to user ID 1 if we could not find any other administrator users. | |
55 $owner_id = !empty($result) ? reset($result) : 1; | |
56 | |
57 // Create two workspaces by default, 'live' and 'stage'. | |
58 Workspace::create([ | |
59 'id' => 'live', | |
60 'label' => 'Live', | |
61 'uid' => $owner_id, | |
62 ])->save(); | |
63 | |
64 Workspace::create([ | |
65 'id' => 'stage', | |
66 'label' => 'Stage', | |
67 'uid' => $owner_id, | |
68 ])->save(); | |
69 } |