function opigno_learning_path_update_8017 in Opigno Learning path 8
Replace module availability fields.
File
- ./
opigno_learning_path.install, line 520 - Install, update and uninstall functions for the module.
Code
function opigno_learning_path_update_8017() {
$entity_type = 'lp_module_availability';
$fields = [
'module_always_available',
'restrict_to_training',
];
$update_manager = Drupal::service('entity.definition_update_manager');
foreach ($fields as $field) {
$definition = $update_manager
->getFieldStorageDefinition($field, $entity_type);
if ($definition) {
$update_manager
->uninstallFieldStorageDefinition($definition);
}
}
$options = [
0 => t('Always available'),
1 => t('Restrict to specific dates for that training'),
];
$definition = BaseFieldDefinition::create('list_string')
->setLabel(t('Module availability'))
->setDescription(t('Set module availability for particular training.'))
->setSetting('allowed_values', $options)
->setDefaultValue(0);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('availability', 'lp_module_availability', 'lp_module_availability', $definition);
}