diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_filter_format.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_filter_format.yml new file mode 100755 index 0000000..474b0d4 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_filter_format.yml @@ -0,0 +1,21 @@ +id: d7_filter_format +label: Drupal 7 filter format configuration +migration_tags: + - Drupal 7 +source: + plugin: d7_filter_format +process: + format: + - + plugin: machine_name + source: name + - + plugin: dedupe_entity + entity_type: filter_format + field: format + length: 32 + name: name + cache: cache + filters: filters +destination: + plugin: entity:filter_format diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FilterFormat.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FilterFormat.php new file mode 100755 index 0000000..7298cbf --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FilterFormat.php @@ -0,0 +1,109 @@ +select('filter_format', 'f') + ->fields('f', array('format', 'name', 'cache', 'status', 'weight')) + // Ignore the plain text format. + ->condition('format', 'plain_text', '<>') + // Why is ordering necessary? + ->orderBy('format'); + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'format' => $this->t('Format ID.'), + 'name' => $this->t('The name of the filter format.'), + 'cache' => $this->t('Flag to indicate whether format is cachable. (1 = cachable, 0 = not cachable).'), + 'status'=>$this->t('The status of the filter format'), + 'weight'=>$this->t('The weight of the filter format'), + ); + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $filters = array(); + $format_original = $row->getSourceProperty('format'); + + if (is_numeric($format_original)) { + $this->format_current = $format_original; + $new_format = $this->format_current; + } + else { + $this->format_current++; + $new_format = $this->format_current; + } + $original_name = $row->getSourceProperty('name'); + + // Find filters for this row. + $filters = $this->database + ->select('filter', 'f', array('fetch' => \PDO::FETCH_ASSOC)) + ->fields('f', array('module', 'name', 'weight', 'status', 'settings')) + ->condition('format', $format_original) + ->condition('name', [ + 'filter_html', + 'filter_autop', + 'filter_url', + 'filter_htmlcorrector', + 'filter_html_escape', + 'php_code', + ], 'IN') + ->condition('status', 1) + ->execute() + ->fetchAllAssoc('name'); + + foreach ($filters as &$filter) { + $filter['settings'] = unserialize($filter['settings']); + } + + $row->setSourceProperty('format', $new_format); + $row->setSourceProperty('filters', $filters); + $row->setSourceProperty('name', 'Drupal 7: ' . $original_name); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['format']['type'] = 'integer'; + return $ids; + } + +} diff --git a/core/modules/migrate_drupal/src/Tests/d7/MigrateFilterFormatTest.php b/core/modules/migrate_drupal/src/Tests/d7/MigrateFilterFormatTest.php new file mode 100644 index 0000000..f08f6a8 --- /dev/null +++ b/core/modules/migrate_drupal/src/Tests/d7/MigrateFilterFormatTest.php @@ -0,0 +1,67 @@ +getDumpDirectory() . '/Filter.php', + $this->getDumpDirectory() . '/FilterFormat.php', + $this->getDumpDirectory() . '/Variable.php', + ); + $this->prepare($migration, $dumps); + $executable = new MigrateExecutable($migration, $this); + $executable->import(); + } + + protected function assertEntity($id, $label, array $enabled_filters) { + /** @var \Drupal\filter\FilterFormatInterface $entity */ + $entity = FilterFormat::load($id); + $this->assertTrue($entity instanceof FilterFormatInterface); + $this->assertIdentical($label, $entity->label()); + // get('filters') will return enabled filters only, not all of them. + $this->assertIdentical($enabled_filters, array_keys($entity->get('filters'))); + } + + /** + * Tests the Drupal 7 filter format to Drupal 8 migration. + */ + public function testFilterFormat() { + $this->assertEntity('drupal_7_custom_text_format', 'Drupal 7: Custom Text format', ['filter_autop', 'filter_html']); + $this->assertEntity('drupal_7_filtered_html', 'Drupal 7: Filtered HTML', ['filter_autop', 'filter_html', 'filter_htmlcorrector', 'filter_url']); + $this->assertEntity('drupal_7_full_html', 'Drupal 7: Full HTML', ['filter_autop', 'filter_htmlcorrector', 'filter_url']); + + // The plain text format is skipped by the source plugin. + $this->assertNull(FilterFormat::load('drupal_7_plain_text')); + } + +}