social_lms_integrator-1.0.0-beta4/modules/social_lms_integrator_enrollment/social_lms_integrator_enrollment.install
modules/social_lms_integrator_enrollment/social_lms_integrator_enrollment.install
<?php
/**
* Adds the enrollment request view for iteration
*/
function social_lms_integrator_enrollment_update_8001() {
$configs_to_install = [
'views.view.iteration_manage_enrollment_requests',
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8001', 'social_lms_integrator_enrollment');
}
}
/**
* Updates views.view.iteration_manage_enrollment_requests view
*/
function social_lms_integrator_enrollment_update_8002() {
$configs_to_install = [
'views.view.iteration_manage_enrollment_requests',
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8002', 'social_lms_integrator_enrollment');
}
}
/**
* Updates views.view.iteration_manage_enrollment_requests view
*/
function social_lms_integrator_enrollment_update_8003() {
$configs_to_install = [
'views.view.iteration_manage_enrollment_requests',
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8003', 'social_lms_integrator_enrollment');
}
}
/**
* Adds new field for welcome message
*/
function social_lms_integrator_enrollment_update_8004() {
$configs_to_install = [
'field.storage.iteration_enrollment.field_welcome_message',
'field.field.iteration_enrollment.iteration_enrollment.field_welcome_message',
'core.entity_form_display.iteration_enrollment.iteration_enrollment.default',
'core.entity_view_display.iteration_enrollment.iteration_enrollment.default'
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8004', 'social_lms_integrator_enrollment');
}
}
/**
* Updates views.view.iteration_manage_enrollment_requests view
*/
function social_lms_integrator_enrollment_update_8005() {
$configs_to_install = [
'views.view.iteration_manage_enrollment_requests',
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8005', 'social_lms_integrator_enrollment');
}
}
/**
* Updates views.view.iteration_manage_enrollment_requests view
*/
function social_lms_integrator_enrollment_update_8006() {
$configs_to_install = [
'views.view.iteration_manage_enrollment_requests',
];
foreach ($configs_to_install as $config_to_install) {
_social_lms_integrator_enrollment_update_or_install_config($config_to_install, '8006', 'social_lms_integrator_enrollment');
}
}
/**
* Delete the view iteration_manage_enrollment_requests.
* This view will be moved to social_lms_integrator_iteration_managers module.
*/
function social_lms_integrator_enrollment_update_8007() {
// Delete unwanted config inside this module.
// Dependency loop.
\Drupal::configFactory()->getEditable('views.view.iteration_manage_enrollment_requests')->delete();
}
function _social_lms_integrator_enrollment_update_or_install_config( String $prefix, String $update_id, String $module) {
$updated = [];
$created = [];
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = \Drupal::service('config.manager');
$files = glob(drupal_get_path('module', $module) . '/config/update_' . $update_id. '/' . $prefix . '*.yml') ;
foreach ($files as $file) {
$raw = file_get_contents($file);
$value = \Drupal\Component\Serialization\Yaml::decode($raw);
if(!is_array($value)) {
throw new \RuntimeException(sprintf('Invalid YAML file %s'), $file);
}
$type = $config_manager->getEntityTypeIdByName(basename($file));
$entity_manager = $config_manager->getEntityTypeManager();
$definition = $entity_manager->getDefinition($type);
$id_key = $definition->getKey('id');
$id = $value[$id_key];
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $entity_storage */
$entity_storage = $entity_manager->getStorage($type);
$entity = $entity_storage->load($id);
if ($entity) {
$entity = $entity_storage->updateFromStorageRecord($entity, $value);
$entity->save();
$updated[] = $id;
}
else {
$entity = $entity_storage->createFromStorageRecord($value);
$entity->save();
$created[] = $id;
}
}
return [
'udpated' => $updated,
'created' => $created,
];
}
