diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index 107495b..537fb79 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -413,7 +413,10 @@ public function addField($table, $field, $spec, $keys_new = array()) { } if ($fixnull) { $spec['not null'] = TRUE; - $this->changeField($table, $field, $field, $spec); + $count = $this->connection->query('SELECT COUNT(*) AS count FROM {' . $table . '}')->fetchAssoc(); + if ($count['count'] == 0) { + $this->changeField($table, $field, $field, $spec); + } } } diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index d76c132..337cd1e 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -124,10 +124,12 @@ protected function installedStorageSchema() { * {@inheritdoc} */ public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) { - return - $this->hasSharedTableStructureChange($entity_type, $original) || - // Detect changes in key or index definitions. - $this->getEntitySchemaData($entity_type, $this->getEntitySchema($entity_type, TRUE)) != $this->loadEntitySchemaData($original); + $shared = $this->hasSharedTableStructureChange($entity_type, $original); + // Detect changes in key or index definitions. + $new = $this->getEntitySchemaData($entity_type, $this->getEntitySchema($entity_type, TRUE)); + $old = $this->loadEntitySchemaData($original); + $schema = $new != $old; + return $shared || $schema; } /** @@ -143,10 +145,10 @@ public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_t * a table has been renamed. */ protected function hasSharedTableStructureChange(EntityTypeInterface $entity_type, EntityTypeInterface $original) { - return - $entity_type->isRevisionable() != $original->isRevisionable() || - $entity_type->isTranslatable() != $original->isTranslatable() || - $this->hasSharedTableNameChanges($entity_type, $original); + $revisionable = $entity_type->isRevisionable() != $original->isRevisionable(); + $translatable = $entity_type->isTranslatable() != $original->isTranslatable(); + $changes = $this->hasSharedTableNameChanges($entity_type, $original); + return $revisionable || $translatable || $changes; } /** diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index e236628..c612fd8 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -37,3 +37,16 @@ function aggregator_update_8001() { /** * @} End of "addtogroup updates-8.0.0-rc". */ + +/** + * Update schema. + */ +function aggregator_update_8002() { + $entity_type = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); + + $entity_type = \Drupal::entityTypeManager()->getStorage('aggregator_item')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/aggregator/src/Entity/Feed.php b/core/modules/aggregator/src/Entity/Feed.php index 834a55e..bc790c6 100644 --- a/core/modules/aggregator/src/Entity/Feed.php +++ b/core/modules/aggregator/src/Entity/Feed.php @@ -2,8 +2,8 @@ namespace Drupal\aggregator\Entity; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\aggregator\FeedInterface; @@ -39,13 +39,14 @@ * render_cache = FALSE, * entity_keys = { * "id" = "fid", + * "revision" = "revision_id", * "label" = "title", * "langcode" = "langcode", * "uuid" = "uuid", * } * ) */ -class Feed extends ContentEntityBase implements FeedInterface { +class Feed extends RevisionableContentEntityBase implements FeedInterface { /** * {@inheritdoc} @@ -142,6 +143,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Title')) ->setDescription(t('The name of the feed (or the name of the website providing the feed).')) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', array( 'type' => 'string_textfield', @@ -154,6 +156,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('URL')) ->setDescription(t('The fully-qualified URL of the feed.')) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setDisplayOptions('form', array( 'type' => 'uri', 'weight' => -3, @@ -170,6 +173,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.')) ->setSetting('unsigned', TRUE) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setSetting('allowed_values', $period) ->setDisplayOptions('form', array( 'type' => 'options_select', @@ -181,6 +185,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Checked')) ->setDescription(t('Last time feed was checked for new items, as Unix timestamp.')) ->setDefaultValue(0) + ->setRevisionable(TRUE) ->setDisplayOptions('view', array( 'label' => 'inline', 'type' => 'timestamp_ago', @@ -191,11 +196,13 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['queued'] = BaseFieldDefinition::create('timestamp') ->setLabel(t('Queued')) ->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.')) - ->setDefaultValue(0); + ->setDefaultValue(0) + ->setRevisionable(TRUE); $fields['link'] = BaseFieldDefinition::create('uri') ->setLabel(t('URL')) ->setDescription(t('The link of the feed.')) + ->setRevisionable(TRUE) ->setDisplayOptions('view', array( 'label' => 'inline', 'weight' => 4, @@ -204,26 +211,31 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['description'] = BaseFieldDefinition::create('string_long') ->setLabel(t('Description')) - ->setDescription(t("The parent website's description that comes from the @description element in the feed.", array('@description' => ''))); + ->setDescription(t("The parent website's description that comes from the @description element in the feed.", array('@description' => ''))) + ->setRevisionable(TRUE); $fields['image'] = BaseFieldDefinition::create('uri') ->setLabel(t('Image')) - ->setDescription(t('An image representing the feed.')); + ->setDescription(t('An image representing the feed.')) + ->setRevisionable(TRUE); $fields['hash'] = BaseFieldDefinition::create('string') ->setLabel(t('Hash')) ->setSetting('is_ascii', TRUE) - ->setDescription(t('Calculated hash of the feed data, used for validating cache.')); + ->setDescription(t('Calculated hash of the feed data, used for validating cache.')) + ->setRevisionable(TRUE); $fields['etag'] = BaseFieldDefinition::create('string') ->setLabel(t('Etag')) - ->setDescription(t('Entity tag HTTP response header, used for validating cache.')); + ->setDescription(t('Entity tag HTTP response header, used for validating cache.')) + ->setRevisionable(TRUE); // This is updated by the fetcher and not when the feed is saved, therefore // it's a timestamp and not a changed field. $fields['modified'] = BaseFieldDefinition::create('timestamp') ->setLabel(t('Modified')) - ->setDescription(t('When the feed was last modified, as a Unix timestamp.')); + ->setDescription(t('When the feed was last modified, as a Unix timestamp.')) + ->setRevisionable(TRUE); return $fields; } diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index 330aacb..0369c28 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -3,10 +3,10 @@ namespace Drupal\aggregator\Entity; use Drupal\Core\Cache\Cache; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\aggregator\ItemInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Url; @@ -29,12 +29,13 @@ * list_cache_tags = { "aggregator_feed_list" }, * entity_keys = { * "id" = "iid", + * "revision" = "revision_id", * "label" = "title", * "langcode" = "langcode", * } * ) */ -class Item extends ContentEntityBase implements ItemInterface { +class Item extends RevisionableContentEntityBase implements ItemInterface { /** * {@inheritdoc} @@ -91,7 +92,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['description'] = BaseFieldDefinition::create('string_long') ->setLabel(t('Description')) - ->setDescription(t('The body of the feed item.')); + ->setDescription(t('The body of the feed item.')) + ->setRevisionable(TRUE); $fields['timestamp'] = BaseFieldDefinition::create('created') ->setLabel(t('Posted on')) diff --git a/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php b/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php index 782ac6f..49759de 100644 --- a/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php +++ b/core/modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php @@ -19,7 +19,7 @@ class AggregatorTitleTest extends KernelTestBase { * * @var array */ - public static $modules = ['file', 'field', 'options', 'aggregator', 'system']; + public static $modules = ['user', 'file', 'field', 'options', 'aggregator', 'system']; /** * The field name that is tested. diff --git a/core/modules/aggregator/tests/src/Kernel/ItemWithoutFeedTest.php b/core/modules/aggregator/tests/src/Kernel/ItemWithoutFeedTest.php index e44bd4f..e76b048 100644 --- a/core/modules/aggregator/tests/src/Kernel/ItemWithoutFeedTest.php +++ b/core/modules/aggregator/tests/src/Kernel/ItemWithoutFeedTest.php @@ -15,7 +15,7 @@ class ItemWithoutFeedTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['aggregator', 'options']; + public static $modules = ['aggregator', 'options', 'user']; /** * {@inheritdoc} diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 3c6fa86..82f28ab 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -134,3 +134,12 @@ function comment_update_8001() { function comment_update_8002() { // Empty update to cause a cache flush. } + +/** + * Update schema. + */ +function comment_update_8003() { + $entity_type = \Drupal::entityTypeManager()->getStorage('comment')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index d626be3..24b458a 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -4,11 +4,11 @@ use Drupal\Component\Utility\Number; use Drupal\Core\Cache\Cache; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\comment\CommentInterface; use Drupal\Core\Entity\EntityChangedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\field\Entity\FieldStorageConfig; use Drupal\user\Entity\User; @@ -40,6 +40,7 @@ * translatable = TRUE, * entity_keys = { * "id" = "cid", + * "revision" = "revision_id", * "bundle" = "comment_type", * "label" = "subject", * "langcode" = "langcode", @@ -57,7 +58,7 @@ * } * ) */ -class Comment extends ContentEntityBase implements CommentInterface { +class Comment extends RevisionableContentEntityBase implements CommentInterface { use EntityChangedTrait; @@ -234,6 +235,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['subject'] = BaseFieldDefinition::create('string') ->setLabel(t('Subject')) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 64) ->setDisplayOptions('form', array( 'type' => 'string_textfield', @@ -246,6 +248,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('User ID')) ->setDescription(t('The user ID of the comment author.')) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('target_type', 'user') ->setDefaultValue(0); @@ -253,18 +256,21 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Name')) ->setDescription(t("The comment author's name.")) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 60) ->setDefaultValue(''); $fields['mail'] = BaseFieldDefinition::create('email') ->setLabel(t('Email')) ->setDescription(t("The comment author's email address.")) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setRevisionable(TRUE); $fields['homepage'] = BaseFieldDefinition::create('uri') ->setLabel(t('Homepage')) ->setDescription(t("The comment author's home page address.")) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) // URIs are not length limited by RFC 2616, but we can only store 255 // characters in our comment DB schema. ->setSetting('max_length', 255); @@ -273,22 +279,26 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Hostname')) ->setDescription(t("The comment author's hostname.")) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 128); $fields['created'] = BaseFieldDefinition::create('created') ->setLabel(t('Created')) ->setDescription(t('The time that the comment was created.')) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setRevisionable(TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the comment was last edited.')) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setRevisionable(TRUE); $fields['status'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Publishing status')) ->setDescription(t('A boolean indicating whether the comment is published.')) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setDefaultValue(TRUE); $fields['thread'] = BaseFieldDefinition::create('string') diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install new file mode 100644 index 0000000..eaaef98 --- /dev/null +++ b/core/modules/contact/contact.install @@ -0,0 +1,10 @@ +getStorage('contact_message')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/contact/src/Entity/Message.php b/core/modules/contact/src/Entity/Message.php index 20f360f..7cc3100 100644 --- a/core/modules/contact/src/Entity/Message.php +++ b/core/modules/contact/src/Entity/Message.php @@ -2,9 +2,9 @@ namespace Drupal\contact\Entity; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\contact\MessageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; /** @@ -23,6 +23,7 @@ * }, * admin_permission = "administer contact forms", * entity_keys = { + * "revision" = "revision_id", * "bundle" = "contact_form", * "uuid" = "uuid", * "langcode" = "langcode" @@ -31,7 +32,7 @@ * field_ui_base_route = "entity.contact_form.edit_form", * ) */ -class Message extends ContentEntityBase implements MessageInterface { +class Message extends RevisionableContentEntityBase implements MessageInterface { /** * {@inheritdoc} diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 05eedf0..4d2d47d 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -120,3 +120,12 @@ function file_requirements($phase) { return $requirements; } + +/** + * Update schema. + */ +function file_update_8003() { + $entity_type = \Drupal::entityTypeManager()->getStorage('file')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/file/file.module b/core/modules/file/file.module index bbf3bff..2cdb53b 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -236,10 +236,12 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E if ($replace == FILE_EXISTS_REPLACE) { $existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri)); if (count($existing_files)) { + /** @var \Drupal\file\FileInterface $existing */ $existing = reset($existing_files); $delete_source = TRUE; $file->fid = $existing->id(); $file->uuid = $existing->uuid(); + $file->revision_id = $existing->getRevisionId(); } } // If we are renaming around an existing file (rather than a directory), diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index da6d7c5..28b4d85 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -2,10 +2,10 @@ namespace Drupal\file\Entity; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityChangedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\file\FileInterface; use Drupal\user\UserInterface; @@ -25,13 +25,14 @@ * base_table = "file_managed", * entity_keys = { * "id" = "fid", + * "revision" = "revision_id", * "label" = "filename", * "langcode" = "langcode", * "uuid" = "uuid" * } * ) */ -class File extends ContentEntityBase implements FileInterface { +class File extends RevisionableContentEntityBase implements FileInterface { use EntityChangedTrait; diff --git a/core/modules/menu_link_content/menu_link_content.install b/core/modules/menu_link_content/menu_link_content.install index 43c75ec..1aa0d2f 100644 --- a/core/modules/menu_link_content/menu_link_content.install +++ b/core/modules/menu_link_content/menu_link_content.install @@ -16,3 +16,12 @@ function menu_link_content_install() { // https://www.drupal.org/node/1965074 module_set_weight('menu_link_content', 1); } + +/** + * Update schema. + */ +function menu_link_content_update_8001() { + $entity_type = \Drupal::entityTypeManager()->getStorage('menu_link_content')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index d70889b..8d4a921 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -2,10 +2,10 @@ namespace Drupal\menu_link_content\Entity; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityChangedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\link\LinkItemInterface; use Drupal\menu_link_content\MenuLinkContentInterface; @@ -34,6 +34,7 @@ * translatable = TRUE, * entity_keys = { * "id" = "id", + * "revision" = "revision_id", * "label" = "title", * "langcode" = "langcode", * "uuid" = "uuid", @@ -46,7 +47,7 @@ * } * ) */ -class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterface { +class MenuLinkContent extends RevisionableContentEntityBase implements MenuLinkContentInterface { use EntityChangedTrait; @@ -253,6 +254,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The text to be used for this link in the menu.')) ->setRequired(TRUE) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('view', array( 'label' => 'hidden', @@ -269,6 +271,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Description')) ->setDescription(t('Shown when hovering over the menu link.')) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('view', array( 'label' => 'hidden', @@ -290,6 +293,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Link')) ->setDescription(t('The location this menu link points to.')) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setSettings(array( 'link_type' => LinkItemInterface::LINK_GENERIC, 'title' => DRUPAL_DISABLED, @@ -357,7 +361,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the menu link was last edited.')) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setRevisionable(TRUE); return $fields; } diff --git a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentDeriverTest.php b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentDeriverTest.php index 12d8d35..49de60a 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentDeriverTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/MenuLinkContentDeriverTest.php @@ -18,7 +18,7 @@ class MenuLinkContentDeriverTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['menu_link_content', 'link', 'system', 'menu_link_content_dynamic_route']; + public static $modules = ['menu_link_content', 'link', 'system', 'menu_link_content_dynamic_route', 'user']; /** * {@inheritdoc} diff --git a/core/modules/menu_link_content/tests/src/Kernel/PathAliasMenuLinkContentTest.php b/core/modules/menu_link_content/tests/src/Kernel/PathAliasMenuLinkContentTest.php index 046deb4..408f60c 100644 --- a/core/modules/menu_link_content/tests/src/Kernel/PathAliasMenuLinkContentTest.php +++ b/core/modules/menu_link_content/tests/src/Kernel/PathAliasMenuLinkContentTest.php @@ -18,7 +18,7 @@ class PathAliasMenuLinkContentTest extends KernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['menu_link_content', 'system', 'link', 'test_page_test']; + public static $modules = ['menu_link_content', 'system', 'link', 'test_page_test', 'user']; /** * {@inheritdoc} diff --git a/core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php b/core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php index 9ec0c65..894abd4 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateRollbackTest.php @@ -20,7 +20,7 @@ class MigrateRollbackTest extends MigrateTestBase { * * @var array */ - public static $modules = ['field', 'taxonomy', 'text']; + public static $modules = ['field', 'taxonomy', 'text', 'user']; /** * {@inheritdoc} diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index 8df408f..5797d8d 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -67,3 +67,12 @@ function shortcut_uninstall() { \Drupal::configFactory()->getEditable('seven.settings')->clear('third_party_settings.shortcut')->save(TRUE); } } + +/** + * Update schema. + */ +function shortcut_update_8001() { + $entity_type = \Drupal::entityTypeManager()->getStorage('shortcut')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 6ddaf05..b8edc86 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -3,9 +3,9 @@ namespace Drupal\shortcut\Entity; use Drupal\Core\Cache\Cache; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\link\LinkItemInterface; use Drupal\shortcut\ShortcutInterface; @@ -33,6 +33,7 @@ * translatable = TRUE, * entity_keys = { * "id" = "id", + * "revision" = "revision_id", * "uuid" = "uuid", * "bundle" = "shortcut_set", * "label" = "title", @@ -47,7 +48,7 @@ * bundle_entity_type = "shortcut_set" * ) */ -class Shortcut extends ContentEntityBase implements ShortcutInterface { +class Shortcut extends RevisionableContentEntityBase implements ShortcutInterface { /** * {@inheritdoc} @@ -121,6 +122,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Name')) ->setDescription(t('The name of the shortcut.')) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', array( @@ -139,6 +141,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Path')) ->setDescription(t('The location this shortcut points to.')) ->setRequired(TRUE) + ->setRevisionable(TRUE) ->setSettings(array( 'link_type' => LinkItemInterface::LINK_INTERNAL, 'title' => DRUPAL_DISABLED, diff --git a/core/modules/shortcut/tests/src/Kernel/ShortcutSevenIntegrationTest.php b/core/modules/shortcut/tests/src/Kernel/ShortcutSevenIntegrationTest.php index 0d58c31..c8517ce 100644 --- a/core/modules/shortcut/tests/src/Kernel/ShortcutSevenIntegrationTest.php +++ b/core/modules/shortcut/tests/src/Kernel/ShortcutSevenIntegrationTest.php @@ -21,6 +21,7 @@ public function testInstallUninstall() { \Drupal::service('theme_installer')->install(['seven']); $this->assertNull($this->config('seven.settings')->get('third_party_settings.shortcut'), 'There are no shortcut settings in seven.settings.'); + \Drupal::service('module_installer')->install(['user']); \Drupal::service('module_installer')->install(['shortcut']); $this->assertTrue($this->config('seven.settings')->get('third_party_settings.shortcut.module_link'), 'The shortcut module_link setting is in seven.settings.'); diff --git a/core/modules/system/src/EntitySchemaUpdater.php b/core/modules/system/src/EntitySchemaUpdater.php new file mode 100644 index 0000000..9adfd84 --- /dev/null +++ b/core/modules/system/src/EntitySchemaUpdater.php @@ -0,0 +1,72 @@ +getStorage($entity_type->id()); + if ($storage instanceof SqlEntityStorageInterface) { + $storage->onEntityTypeCreate($entity_type); + } + } + + public function addRevisionField(EntityTypeInterface $entity_type) { + $revision_id = BaseFieldDefinition::create('integer') + ->setLabel(new TranslatableMarkup('Revision ID')) + ->setReadOnly(TRUE) + ->setSetting('unsigned', TRUE); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition($entity_type->getKey('revision'), $entity_type->id(), $entity_type->id(), $revision_id); + + $revision_created = BaseFieldDefinition::create('created') + ->setLabel(t('Revision create time')) + ->setDescription(t('The time that the current revision was created.')) + ->setRevisionable(TRUE); + \Drupal::entityDefinitionUpdateManager() + ->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); + \Drupal::entityDefinitionUpdateManager() + ->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, + ], + ]); + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition("revision_log_message", $entity_type->id(), $entity_type->id(), $revision_log_message); + + $entity_field_manager = \Drupal::service('entity_field.manager'); + /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $definitions */ + $entity_field_manager->clearCachedFieldDefinitions(); + + \Drupal::service('entity.last_installed_schema.repository')->setLastInstalledDefinition($entity_type); + } + +} diff --git a/core/modules/system/src/EntitySchemaUpdaterInterface.php b/core/modules/system/src/EntitySchemaUpdaterInterface.php new file mode 100644 index 0000000..65f7c23 --- /dev/null +++ b/core/modules/system/src/EntitySchemaUpdaterInterface.php @@ -0,0 +1,19 @@ +getDefinitions()) as $entity_type_id) { - $manager->updateEntityType($manager->getEntityType($entity_type_id)); - } + //$manager = \Drupal::entityDefinitionUpdateManager(); + //foreach (array_keys(\Drupal::entityManager() + // ->getDefinitions()) as $entity_type_id) { + // $manager->updateEntityType($manager->getEntityType($entity_type_id)); + //} } /** diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index c70889d..f55984f 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -43,3 +43,5 @@ services: arguments: ['@theme_handler', '@cache_tags.invalidator'] tags: - { name: event_subscriber } + system.entity_schema_updater: + class: Drupal\system\EntitySchemaUpdater diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 2e41e2d..8ebc717 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -2,10 +2,10 @@ namespace Drupal\taxonomy\Entity; -use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\EntityChangedTrait; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\RevisionableContentEntityBase; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\taxonomy\TermInterface; @@ -34,6 +34,7 @@ * translatable = TRUE, * entity_keys = { * "id" = "tid", + * "revision" = "revision_id", * "bundle" = "vid", * "label" = "name", * "langcode" = "langcode", @@ -50,7 +51,7 @@ * permission_granularity = "bundle" * ) */ -class Term extends ContentEntityBase implements TermInterface { +class Term extends RevisionableContentEntityBase implements TermInterface { use EntityChangedTrait; @@ -118,6 +119,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setLabel(t('Name')) ->setDescription(t('The term name.')) ->setTranslatable(TRUE) + ->setRevisionable(TRUE) ->setRequired(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('view', array( @@ -134,6 +136,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['description'] = BaseFieldDefinition::create('text_long') ->setLabel(t('Description')) ->setDescription(t('A description of the term.')) + ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setDisplayOptions('view', array( 'label' => 'hidden', @@ -162,7 +165,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the term was last edited.')) - ->setTranslatable(TRUE); + ->setTranslatable(TRUE) + ->setRevisionable(TRUE); return $fields; } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install new file mode 100644 index 0000000..973de6c --- /dev/null +++ b/core/modules/taxonomy/taxonomy.install @@ -0,0 +1,10 @@ +getStorage('taxonomy_term')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->createTables($entity_type); + \Drupal::service('system.entity_schema_updater')->addRevisionField($entity_type); +} diff --git a/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php b/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php index 0cdc303..c655c11 100644 --- a/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php @@ -41,6 +41,7 @@ class MenuLinkTreeTest extends KernelTestBase { 'menu_link_content', 'field', 'link', + 'user' ); /** @@ -49,6 +50,7 @@ class MenuLinkTreeTest extends KernelTestBase { protected function setUp() { parent::setUp(); \Drupal::service('router.builder')->rebuild(); + $this->installEntitySchema('user'); $this->installEntitySchema('menu_link_content'); $this->linkTree = $this->container->get('menu.link_tree');