block_content.install 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the block_content module.
  5. */
  6. use Drupal\Core\Field\BaseFieldDefinition;
  7. /**
  8. * Add 'revision_translation_affected' field to 'block_content' entities.
  9. */
  10. function block_content_update_8001() {
  11. // Install the definition that this field had in
  12. // \Drupal\block_content\Entity\BlockContent::baseFieldDefinitions()
  13. // at the time that this update function was written. If/when code is
  14. // deployed that changes that definition, the corresponding module must
  15. // implement an update function that invokes
  16. // \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
  17. // with the new definition.
  18. $storage_definition = BaseFieldDefinition::create('boolean')
  19. ->setLabel(t('Revision translation affected'))
  20. ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
  21. ->setReadOnly(TRUE)
  22. ->setRevisionable(TRUE)
  23. ->setTranslatable(TRUE);
  24. \Drupal::entityDefinitionUpdateManager()
  25. ->installFieldStorageDefinition('revision_translation_affected', 'block_content', 'block_content', $storage_definition);
  26. }
  27. /**
  28. * Generalizes the d6_block_content_type and d6_block_content_body_field
  29. * migrations.
  30. */
  31. function block_content_update_8002() {
  32. // Removed in issue #2569605. The Migrate and Migrate Drupal modules are
  33. // marked experimental and do not need to support the update path until they
  34. // are stable.
  35. // @see https://www.drupal.org/node/2569469
  36. }
  37. /**
  38. * Add 'revision_created' and 'revision_user' fields to 'block_content' entities.
  39. */
  40. function block_content_update_8003() {
  41. $revision_created = BaseFieldDefinition::create('created')
  42. ->setLabel(t('Revision create time'))
  43. ->setDescription(t('The time that the current revision was created.'))
  44. ->setRevisionable(TRUE);
  45. \Drupal::entityDefinitionUpdateManager()
  46. ->installFieldStorageDefinition('revision_created', 'block_content', 'block_content', $revision_created);
  47. $revision_user = BaseFieldDefinition::create('entity_reference')
  48. ->setLabel(t('Revision user'))
  49. ->setDescription(t('The user ID of the author of the current revision.'))
  50. ->setSetting('target_type', 'user')
  51. ->setRevisionable(TRUE);
  52. \Drupal::entityDefinitionUpdateManager()
  53. ->installFieldStorageDefinition('revision_user', 'block_content', 'block_content', $revision_user);
  54. }
  55. /**
  56. * Fix the block_content entity type to specify its revision data table.
  57. */
  58. function block_content_update_8300() {
  59. $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  60. $entity_type = $definition_update_manager->getEntityType('block_content');
  61. $entity_type->set('revision_data_table', 'block_content_field_revision');
  62. $definition_update_manager->updateEntityType($entity_type);
  63. }