workspaces.install
Same filename in other branches
Contains install, update and uninstall functions for the Workspaces module.
File
-
core/
modules/ workspaces/ workspaces.install
View source
<?php
/**
* @file
* Contains install, update and uninstall functions for the Workspaces module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\workspaces\Entity\Workspace;
/**
* Implements hook_requirements().
*/
function workspaces_requirements($phase) : array {
$requirements = [];
if ($phase === 'install') {
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 <a href=":link">upgrade path</a> page for more information on how to upgrade.', [
':link' => 'https://www.drupal.org/node/2987783',
]),
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function workspaces_install() : void {
// Set the owner of these default workspaces to be first user 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()
->accessCheck(FALSE)
->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 a 'stage' workspace by default.
Workspace::create([
'id' => 'stage',
'label' => 'Stage',
'uid' => $owner_id,
])->save();
}
/**
* Implements hook_schema().
*/
function workspaces_schema() : array {
$schema['workspace_association'] = [
'description' => 'Stores the association between entity revisions and their workspace.',
'fields' => [
'workspace' => [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The workspace ID.',
],
'target_entity_type_id' => [
'type' => 'varchar_ascii',
'length' => EntityTypeInterface::ID_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
'description' => 'The ID of the associated entity type.',
],
'target_entity_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The ID of the associated entity.',
],
'target_entity_id_string' => [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The string ID of the associated entity.',
],
'target_entity_revision_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The revision ID of the associated entity.',
],
],
'primary key' => [
'workspace',
'target_entity_type_id',
'target_entity_id',
'target_entity_id_string',
],
'indexes' => [
'target_entity_revision_id' => [
'target_entity_revision_id',
],
],
];
return $schema;
}
/**
* Implements hook_update_last_removed().
*/
function workspaces_update_last_removed() : int {
return 8803;
}
/**
* Update workspace associations to support entity types with string IDs.
*/
function workspaces_update_11101() : void {
$schema = \Drupal::database()->schema();
$target_id_spec = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The ID of the associated entity.',
];
$schema->changeField('workspace_association', 'target_entity_id', 'target_entity_id', $target_id_spec);
$target_id_string_spec = [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The string ID of the associated entity.',
];
$schema->addField('workspace_association', 'target_entity_id_string', $target_id_string_spec, [
'primary key' => [
'workspace',
'target_entity_type_id',
'target_entity_id',
'target_entity_id_string',
],
]);
}
/**
* Install the new Workspaces UI module.
*/
function workspaces_update_11102() : void {
\Drupal::service('module_installer')->install([
'workspaces_ui',
]);
}
Functions
Title | Deprecated | Summary |
---|---|---|
workspaces_install | Implements hook_install(). | |
workspaces_requirements | Implements hook_requirements(). | |
workspaces_schema | Implements hook_schema(). | |
workspaces_update_11101 | Update workspace associations to support entity types with string IDs. | |
workspaces_update_11102 | Install the new Workspaces UI module. | |
workspaces_update_last_removed | Implements hook_update_last_removed(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.