function opigno_module_update_8002 in Opigno module 8
Make OpignoAnswer revisionable.
File
- ./
opigno_module.install, line 334 - Opigno module app install/update functionality.
Code
function opigno_module_update_8002() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Add revisionable metadata fields to the opigno_answer entity type.
$entity_type = $definition_update_manager
->getEntityType('opigno_answer');
$entity_type_id = $entity_type
->id();
$revision_metadata_keys = [
'revision_user' => 'revision_user',
'revision_created' => 'revision_created',
'revision_log_message' => 'revision_log_message',
];
$entity_type
->set('revision_metadata_keys', $revision_metadata_keys);
$definition_update_manager
->updateEntityType($entity_type);
// Add the revision metadata fields.
$revision_created = BaseFieldDefinition::create('created')
->setLabel(t('Revision create time'))
->setDescription(t('The time that the current revision was created.'))
->setRevisionable(TRUE);
$definition_update_manager
->installFieldStorageDefinition('revision_created', $entity_type_id, $entity_type_id, $revision_created);
$revision_user = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setRevisionable(TRUE);
$definition_update_manager
->installFieldStorageDefinition('revision_user', $entity_type_id, $entity_type_id, $revision_user);
$revision_log_message = BaseFieldDefinition::create('string_long')
->setLabel(t('Revision log message'))
->setDescription(t('Briefly describe the changes you have made.'))
->setRevisionable(TRUE)
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textarea',
'weight' => 25,
'settings' => [
'rows' => 4,
],
]);
$definition_update_manager
->installFieldStorageDefinition('revision_log_message', $entity_type_id, $entity_type_id, $revision_log_message);
}