You are here

function bibcite_entity_update_8014 in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/bibcite_entity.install \bibcite_entity_update_8014()

Update existing reference entities data to be revisionable.

File

modules/bibcite_entity/bibcite_entity.install, line 512
Module installation hooks implementation.

Code

function bibcite_entity_update_8014(&$sandbox) {
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();

  // Mark various fields as revisionable.

  /** @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface $last_installed_schema_repository */
  $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
  $field_storage_definitions = $last_installed_schema_repository
    ->getLastInstalledFieldStorageDefinitions('bibcite_reference');
  $fields_to_update = [
    'uid',
    'langcode',
    'title',
    'created',
    'changed',
    'keywords',
    'author',
    'status',
    'bibcite_abst_e',
    'bibcite_abst_f',
    'bibcite_notes',
    'bibcite_custom1',
    'bibcite_custom2',
    'bibcite_custom3',
    'bibcite_custom4',
    'bibcite_custom5',
    'bibcite_custom6',
    'bibcite_custom7',
    'bibcite_auth_address',
    'bibcite_year',
    'bibcite_secondary_title',
    'bibcite_volume',
    'bibcite_edition',
    'bibcite_section',
    'bibcite_issue',
    'bibcite_number_of_volumes',
    'bibcite_number',
    'bibcite_pages',
    'bibcite_date',
    'bibcite_type_of_work',
    'bibcite_lang',
    'bibcite_reprint_edition',
    'bibcite_publisher',
    'bibcite_place_published',
    'bibcite_issn',
    'bibcite_isbn',
    'bibcite_accession_number',
    'bibcite_call_number',
    'bibcite_other_number',
    'bibcite_citekey',
    'bibcite_url',
    'bibcite_doi',
    'bibcite_research_notes',
    'bibcite_tertiary_title',
    'bibcite_short_title',
    'bibcite_alternate_title',
    'bibcite_translated_title',
    'bibcite_original_publication',
    'bibcite_other_author_affiliations',
    'bibcite_remote_db_name',
    'bibcite_remote_db_provider',
    'bibcite_label',
    'bibcite_access_date',
    'bibcite_refereed',
    'bibcite_pmid',
  ];
  foreach ($fields_to_update as $field_name) {
    $field_storage_definitions[$field_name]
      ->setRevisionable(TRUE);
  }
  $field_storage_definitions['revision_id'] = BaseFieldDefinition::create('integer')
    ->setName('revision_id')
    ->setTargetEntityTypeId('bibcite_reference')
    ->setTargetBundle(NULL)
    ->setLabel(t('Revision ID'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE);
  $field_storage_definitions['revision_default'] = BaseFieldDefinition::create('boolean')
    ->setName('revision_default')
    ->setTargetEntityTypeId('bibcite_reference')
    ->setTargetBundle(NULL)
    ->setLabel(t('Default revision'))
    ->setDescription(t('A flag indicating whether this was a default revision when it was saved.'))
    ->setStorageRequired(TRUE)
    ->setInternal(TRUE)
    ->setTranslatable(FALSE)
    ->setRevisionable(TRUE);
  $entity_type = $definition_update_manager
    ->getEntityType('bibcite_reference');
  $entity_keys = $entity_type
    ->getKeys();
  $entity_keys['revision'] = 'revision_id';
  $entity_type
    ->set('entity_keys', $entity_keys);
  $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);
  $entity_type
    ->set('revision_table', 'bibcite_reference_revision');
  $definition_update_manager
    ->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
}