You are here

function entityqueue_update_8005 in Entityqueue 8

Add the revision metadata fields to subqueues.

File

./entityqueue.install, line 106
Install, update and uninstall functions for the Entityqueue module.

Code

function entityqueue_update_8005() {

  // We are adding these fields before the conversion to revisionable in order
  // to be able to use initial values from the existing 'created' and 'uid'
  // fields.
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $definition_update_manager
    ->getEntityType('entity_subqueue');

  // Add the revision metadata keys to the entity_subqueue entity type.
  $revision_metadata_keys = [
    'revision_default' => 'revision_default',
    '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);
  $revision_created = BaseFieldDefinition::create('created')
    ->setLabel(new TranslatableMarkup('Revision create time'))
    ->setDescription(new TranslatableMarkup('The time that the current revision was created.'))
    ->setRevisionable(TRUE)
    ->setInitialValueFromField('created');
  $definition_update_manager
    ->installFieldStorageDefinition('revision_created', 'entity_subqueue', 'entity_subqueue', $revision_created);
  $revision_user = BaseFieldDefinition::create('entity_reference')
    ->setLabel(new TranslatableMarkup('Revision user'))
    ->setDescription(new TranslatableMarkup('The user ID of the author of the current revision.'))
    ->setSetting('target_type', 'user')
    ->setRevisionable(TRUE)
    ->setInitialValueFromField('uid');
  $definition_update_manager
    ->installFieldStorageDefinition('revision_user', 'entity_subqueue', 'entity_subqueue', $revision_user);
  $revision_log_message = BaseFieldDefinition::create('string_long')
    ->setLabel(new TranslatableMarkup('Revision log message'))
    ->setDescription(new TranslatableMarkup('Briefly describe the changes you have made.'))
    ->setRevisionable(TRUE)
    ->setDefaultValue('');
  $definition_update_manager
    ->installFieldStorageDefinition('revision_log_message', 'entity_subqueue', 'entity_subqueue', $revision_log_message);
  return t('The revision metadata fields have been added to Entity Subqueues.');
}