opigno_moxtra.install in Opigno Moxtra 8
Same filename and directory in other branches
Install, update and uninstall functions for the Opigno Moxtra module.
File
opigno_moxtra.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Opigno Moxtra module.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Creates the collaborative workspace field in a training groups.
*/
function opigno_moxtra_install($is_syncing) {
if (!$is_syncing) {
$config_path = drupal_get_path('module', 'opigno_moxtra') . '/config/install';
$storage = new FileStorage($config_path);
$data = $storage
->read('field.storage.group.field_workspace');
if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
FieldStorageConfig::create($data)
->save();
}
$data = $storage
->read('field.field.group.learning_path.field_workspace');
if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
FieldConfig::create($data)
->save();
}
_opigno_moxtra_set_meeting_permissions();
}
}
/**
* Set meeting permissions.
*/
function _opigno_moxtra_set_meeting_permissions() {
// Allow content managers to start meeting.
$role = Role::load('content_manager');
$role
->grantPermission('start meeting');
$role
->save();
// Allow live meeting managers to start meeting.
$role = Role::load('collaborative_features');
$role
->grantPermission('start meeting');
$role
->save();
// Allow users to view ILT entities.
$role = Role::load(RoleInterface::AUTHENTICATED_ID);
$role
->grantPermission('view meeting entities');
$role
->save();
}
/**
* Removes module configurations during uninstall.
*/
function opigno_moxtra_uninstall() {
// Remove module configs.
$configs = [
'core.entity_form_display.opigno_calendar_event.meeting_calendar_event.default',
'core.entity_form_display.opigno_calendar_event.meeting_calendar_event.embedded_widget',
'core.entity_view_display.opigno_calendar_event.meeting_calendar_event.default',
'core.entity_view_display.opigno_calendar_event.meeting_calendar_event.embedded_display',
'field.field.group.learning_path.field_workspace',
'field.field.opigno_calendar_event.meeting_calendar_event.field_calendar_event_members',
'field.field.opigno_calendar_event.meeting_calendar_event.field_meeting',
'field.storage.group.field_workspace',
'field.storage.opigno_calendar_event.field_meeting',
'group.content_type.group_content_type_78b202c274a0f',
'opigno_calendar_event.type.meeting_calendar_event',
'opigno_moxtra.settings',
'user.role.collaborative_features',
];
foreach ($configs as $config) {
try {
\Drupal::configFactory()
->getEditable($config)
->delete();
} catch (Exception $e) {
\Drupal::logger('opigno_moxtra')
->error($e
->getMessage());
}
}
}
/**
* Creates the opigno_moxtra_workspace entity type.
*/
function opigno_moxtra_update_8001() {
$schema = \Drupal::database()
->schema();
if (!$schema
->tableExists('opigno_moxtra_workspace')) {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type_manager
->clearCachedDefinitions();
$definition = $entity_type_manager
->getDefinition('opigno_moxtra_workspace');
$entity_definition_update_manager
->installEntityType($definition);
}
}
/**
* Creates the collaborative workspace field in training groups.
*/
function opigno_moxtra_update_8002() {
$config_path = drupal_get_path('module', 'opigno_moxtra') . '/config/install';
$storage = new FileStorage($config_path);
$data = $storage
->read('field.storage.group.field_workspace');
if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
FieldStorageConfig::create($data)
->save();
}
$data = $storage
->read('field.field.group.learning_path.field_workspace');
if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
FieldConfig::create($data)
->save();
}
}
/**
* Creates the members field in workspaces.
*/
function opigno_moxtra_update_8003() {
// Create a new field definition.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Members'))
->setDescription(t('The members of the Workspace entity.'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('members', 'opigno_moxtra_workspace', 'opigno_moxtra_workspace', $field);
}
/**
* Creates the opigno_moxtra_meeting entity type.
*/
function opigno_moxtra_update_8004() {
$schema = \Drupal::database()
->schema();
if (!$schema
->tableExists('opigno_moxtra_meeting')) {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type_manager
->clearCachedDefinitions();
$definition = $entity_type_manager
->getDefinition('opigno_moxtra_meeting');
$entity_definition_update_manager
->installEntityType($definition);
}
}
/**
* Creates the training field in the meetings.
*/
function opigno_moxtra_update_8005() {
// Create a new field definition.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Related training'))
->setDescription(t('The related training of the Meeting entity.'))
->setSettings([
'target_type' => 'group',
'handler' => 'default:group',
'handler_settings' => [
'target_bundles' => [
'learning_path' => 'learning_path',
],
'sort' => [
'field' => '_none',
],
],
]);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('training', 'opigno_moxtra_meeting', 'opigno_moxtra_meeting', $field);
}
/**
* Creates the calendar event field in the meetings.
*/
function opigno_moxtra_update_8006() {
// Create a new field definition.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Related calendar event'))
->setDescription(t('The related calendar event of the Meeting entity.'))
->setSettings([
'target_type' => 'opigno_calendar_event',
'handler' => 'default',
]);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('calendar_event', 'opigno_moxtra_meeting', 'opigno_moxtra_meeting', $field);
}
/**
* Creates the opigno_moxtra_meeting_result entity type.
*/
function opigno_moxtra_update_8007() {
$schema = \Drupal::database()
->schema();
if (!$schema
->tableExists('opigno_moxtra_meeting_result')) {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type_manager
->clearCachedDefinitions();
$definition = $entity_type_manager
->getDefinition('opigno_moxtra_meeting_result');
$entity_definition_update_manager
->installEntityType($definition);
}
}
/**
* Creates the live meeting calendar event type.
*/
function opigno_moxtra_update_8008() {
$config_path = drupal_get_path('module', 'opigno_moxtra') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('opigno_calendar_event.type.meeting_calendar_event');
$config_storage
->write('opigno_calendar_event.type.meeting_calendar_event', $data);
$data = $storage
->read('field.storage.opigno_calendar_event.field_meeting');
if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
FieldStorageConfig::create($data)
->save();
}
$data = $storage
->read('field.field.opigno_calendar_event.meeting_calendar_event.field_meeting');
if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
FieldConfig::create($data)
->save();
}
$data = $storage
->read('field.field.opigno_calendar_event.meeting_calendar_event.field_calendar_event_members');
if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
FieldConfig::create($data)
->save();
}
}
/**
* Creates the notified members field in the meetings.
*/
function opigno_moxtra_update_8009() {
// Create a new field definition.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Notified Members'))
->setDescription(t('Members of the Meeting entity that received notification by email.'))
->setSettings([
'target_type' => 'user',
'handler' => 'default',
])
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('notified_members', 'opigno_moxtra_meeting', 'opigno_moxtra_meeting', $field);
}
/**
* Creates the auto_register field in workspaces.
*/
function opigno_moxtra_update_8010() {
// Create a new field definition.
$field = BaseFieldDefinition::create('boolean')
->setLabel(t('Automatically register'))
->setDescription(t('Automatically register all users of that training.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'weight' => 2,
]);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('auto_register', 'opigno_moxtra_workspace', 'opigno_moxtra_workspace', $field);
}
/**
* Creates the training field in the meetings.
*/
function opigno_moxtra_update_8011() {
// Create a new field definition.
$field = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Training'))
->setDescription(t('The related Training of the Workspace entity.'))
->setSettings([
'target_type' => 'group',
'handler' => 'default:group',
'handler_settings' => [
'target_bundles' => [
'learning_path' => 'learning_path',
],
'sort' => [
'field' => '_none',
],
],
'default_value' => 0,
])
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Install the new definition.
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('training', 'opigno_moxtra_workspace', 'opigno_moxtra_workspace', $field);
}
/**
* Grand permissions for Content manager global role.
*/
function opigno_moxtra_update_8012() {
}
/**
* Creates create cronjobs.
*/
function opigno_moxtra_update_8013() {
// Enable new module opigno_cron.
if (!\Drupal::moduleHandler()
->moduleExists('opigno_cron')) {
\Drupal::service('module_installer')
->install([
'opigno_cron',
]);
}
// Add new cron configuretions.
$config_path = drupal_get_path('module', 'opigno_moxtra') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('ultimate_cron.job.opigno_moxtra_save_meeting_records');
$config_storage
->write('ultimate_cron.job.opigno_moxtra_save_meeting_records', $data);
$data = $storage
->read('ultimate_cron.job.opigno_moxtra_meeting_notification');
$config_storage
->write('ultimate_cron.job.opigno_moxtra_meeting_notification', $data);
}
/**
* Creates create cronjobs.
*/
function opigno_moxtra_update_8014() {
// Add new cron configuretions.
$config_path = drupal_get_path('module', 'opigno_moxtra') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('user.role.collaborative_features');
$config_storage
->write('user.role.collaborative_features', $data);
}
/**
* Grant permission to view meeting for auth users.
*/
function opigno_moxtra_update_8015() {
}
/**
* Grand permissions for Content manager global role.
* Grant permission to view meeting for auth users.
* Grand permissions for collaborative_features role.
*/
function opigno_moxtra_update_8016() {
_opigno_moxtra_set_meeting_permissions();
}
Functions
Name | Description |
---|---|
opigno_moxtra_install | Creates the collaborative workspace field in a training groups. |
opigno_moxtra_uninstall | Removes module configurations during uninstall. |
opigno_moxtra_update_8001 | Creates the opigno_moxtra_workspace entity type. |
opigno_moxtra_update_8002 | Creates the collaborative workspace field in training groups. |
opigno_moxtra_update_8003 | Creates the members field in workspaces. |
opigno_moxtra_update_8004 | Creates the opigno_moxtra_meeting entity type. |
opigno_moxtra_update_8005 | Creates the training field in the meetings. |
opigno_moxtra_update_8006 | Creates the calendar event field in the meetings. |
opigno_moxtra_update_8007 | Creates the opigno_moxtra_meeting_result entity type. |
opigno_moxtra_update_8008 | Creates the live meeting calendar event type. |
opigno_moxtra_update_8009 | Creates the notified members field in the meetings. |
opigno_moxtra_update_8010 | Creates the auto_register field in workspaces. |
opigno_moxtra_update_8011 | Creates the training field in the meetings. |
opigno_moxtra_update_8012 | Grand permissions for Content manager global role. |
opigno_moxtra_update_8013 | Creates create cronjobs. |
opigno_moxtra_update_8014 | Creates create cronjobs. |
opigno_moxtra_update_8015 | Grant permission to view meeting for auth users. |
opigno_moxtra_update_8016 | Grand permissions for Content manager global role. Grant permission to view meeting for auth users. Grand permissions for collaborative_features role. |
_opigno_moxtra_set_meeting_permissions | Set meeting permissions. |