annotate core/modules/workspaces/workspaces.install @ 19:fa3358dc1485 tip

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