5 * Contains install, update and uninstall functions for the Workspaces module.
8 use Drupal\workspaces\Entity\Workspace;
11 * Implements hook_requirements().
13 function workspaces_requirements($phase) {
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.'),
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',
36 * Implements hook_install().
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)
45 if (!empty($admin_roles)) {
46 $query = \Drupal::entityTypeManager()->getStorage('user')->getQuery()
47 ->condition('roles', $admin_roles, 'IN')
48 ->condition('status', 1)
51 $result = $query->execute();
54 // Default to user ID 1 if we could not find any other administrator users.
55 $owner_id = !empty($result) ? reset($result) : 1;
57 // Create two workspaces by default, 'live' and 'stage'.