X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fworkspaces%2Fworkspaces.install;fp=web%2Fcore%2Fmodules%2Fworkspaces%2Fworkspaces.install;h=7bcc18b6410330fa010fff3d6f6f2b2d963dfe86;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/workspaces/workspaces.install b/web/core/modules/workspaces/workspaces.install new file mode 100644 index 000000000..7bcc18b64 --- /dev/null +++ b/web/core/modules/workspaces/workspaces.install @@ -0,0 +1,69 @@ +moduleExists('content_moderation')) { + $requirements['content_moderation_incompatibility'] = [ + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Workspaces can not be installed when Content Moderation is also installed.'), + ]; + } + if (\Drupal::moduleHandler()->moduleExists('workspace')) { + $requirements['workspace_incompatibility'] = [ + 'severity' => REQUIREMENT_ERROR, + 'description' => t('Workspaces can not be installed when the contributed Workspace module is also installed. See the upgrade path page for more information on how to upgrade.', [ + ':link' => 'https://www.drupal.org/node/2987783', + ]), + ]; + } + } + + return $requirements; +} + +/** + * Implements hook_install(). + */ +function workspaces_install() { + // Set the owner of these default workspaces to be first user which which has + // the 'administrator' role. This way we avoid hard coding user ID 1 for sites + // that prefer to not give it any special meaning. + $admin_roles = \Drupal::entityTypeManager()->getStorage('user_role')->getQuery() + ->condition('is_admin', TRUE) + ->execute(); + if (!empty($admin_roles)) { + $query = \Drupal::entityTypeManager()->getStorage('user')->getQuery() + ->condition('roles', $admin_roles, 'IN') + ->condition('status', 1) + ->sort('uid', 'ASC') + ->range(0, 1); + $result = $query->execute(); + } + + // Default to user ID 1 if we could not find any other administrator users. + $owner_id = !empty($result) ? reset($result) : 1; + + // Create two workspaces by default, 'live' and 'stage'. + Workspace::create([ + 'id' => 'live', + 'label' => 'Live', + 'uid' => $owner_id, + ])->save(); + + Workspace::create([ + 'id' => 'stage', + 'label' => 'Stage', + 'uid' => $owner_id, + ])->save(); +}