summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2016-08-26 14:15:50 +0100
committerAlex Pott2016-08-26 14:16:14 +0100
commit3ee04b473198505af763fde15ca2eed69ee6e90f (patch)
tree5344fcfb257ba2f8acacff442f94cdb6918d91b5
parentc5ce86234f84acab47b7dc892b55504536875ccd (diff)
Issue #2705531 by Jo Fitzgerald: View mode migration rollback fails
(cherry picked from commit fd8e8afc1649ae8232d7d7a75a227f57d163ba09)
-rw-r--r--core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php52
-rw-r--r--core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php8
2 files changed, 60 insertions, 0 deletions
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php
new file mode 100644
index 0000000..b069387
--- /dev/null
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/RollbackViewModesTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\Tests\field\Kernel\Migrate\d7;
+
+use Drupal\Core\Entity\Entity\EntityViewMode;
+use Drupal\migrate\MigrateExecutable;
+
+/**
+ * Migrates and rolls back Drupal 7 view modes.
+ *
+ * @group field
+ */
+class RollbackViewModesTest extends MigrateViewModesTest {
+
+ /**
+ * Tests migrating D7 view modes, then rolling back.
+ */
+ public function testMigration() {
+ // Test that the view modes have migrated (prior to rollback).
+ parent::testMigration();
+
+ $this->executeRollback('d7_view_modes');
+
+ // Check that view modes have been rolled back.
+ $view_mode_ids = [
+ 'comment.full',
+ 'node.teaser',
+ 'node.full',
+ 'user.full',
+ ];
+ foreach ($view_mode_ids as $view_mode_id) {
+ $this->assertNull(EntityViewMode::load($view_mode_id));
+ }
+ }
+
+ /**
+ * Executes a single rollback.
+ *
+ * @param string|\Drupal\migrate\Plugin\MigrationInterface $migration
+ * The migration to rollback, or its ID.
+ */
+ protected function executeRollback($migration) {
+ if (is_string($migration)) {
+ $this->migration = $this->getMigration($migration);
+ }
+ else {
+ $this->migration = $migration;
+ }
+ (new MigrateExecutable($this->migration, $this))->rollback();
+ }
+
+}
diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php
index 810152a..fad171b 100644
--- a/core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php
+++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityViewMode.php
@@ -20,4 +20,12 @@ class EntityViewMode extends EntityConfigBase {
return $ids;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function rollback(array $destination_identifier) {
+ $destination_identifier = implode('.', $destination_identifier);
+ parent::rollback(array($destination_identifier));
+ }
+
}