Loading markdown.module +25 −0 Original line number Diff line number Diff line Loading @@ -129,6 +129,31 @@ function markdown_migration_plugins_alter(array &$migrations) { // Add mapping from filter_markdown to markdown for D7 migrations. $migration['process']['filters']['process']['id']['map']['filter_markdown'] = 'markdown'; // Copied from https://www.drupal.org/project/migmag. // @see \Drupal\migmag\Utility\MigMagMigrationUtility::getAssociativeMigrationProcess() $get_associative_migration_process = function($process_pipeline): array { if (is_string($process_pipeline)) { return [['plugin' => 'get', 'source' => $process_pipeline]]; } elseif (array_key_exists('plugin', $process_pipeline)) { $process_pipeline = [$process_pipeline]; } return $process_pipeline; }; // We have to generate settings for the markdown filter. $filter_plugin_settings_processes = $get_associative_migration_process($migrations['d7_filter_format']['process']['filters']['process']['settings']); $filter_plugin_settings_processes[] = [ 'plugin' => 'markdown_settings_generator', ]; $migrations['d7_filter_format']['process']['filters']['process']['settings'] = $filter_plugin_settings_processes; // markdown_settings_generator needs to know the other filters that // enabled in order to generate valid settings. $migrations['d7_filter_format']['process']['filters']['include_source'] = TRUE; $migrations['d7_filter_format']['process']['filters']['source_key'] = 'source_format'; } } Loading src/Plugin/migrate/process/MarkdownSettingsGenerator.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?php namespace Drupal\markdown\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * @MigrateProcessPlugin( * id = "markdown_settings_generator", * handle_multiples = TRUE * ) */ class MarkdownSettingsGenerator extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if ($row->getDestinationProperty('id') === 'markdown') { $parser_manager = \Drupal::service('plugin.manager.markdown.parser'); // The markdown module during installation will automatically detect the // available parsers and select a default. // @see markdown_requirements() // @todo Add support for generating valid configuration for other parsers? if ($parser_manager->getDefaultParser()->getPluginId() === 'commonmark') { // @see markdown_migration_plugins_alter() $source_format = $row->getSourceProperty('source_format'); $enabled_filters = array_column($source_format['filters'], 'name'); $value = [ 'id' => 'commonmark', 'enabled' => TRUE, 'render_strategy' => [ 'type' => 'filter_output', 'custom_allowed_html' => '', 'plugins' => [ 'commonmark' => TRUE, // Footnotes were supported by default in the D7 version. 'commonmark-footnotes' => TRUE, // Enable Markdown support for specific filters if the filters are // enabled. 'filter_align' => in_array('filter_align', $enabled_filters), 'filter_caption' => in_array('filter_caption', $enabled_filters), 'media_embed' => in_array('filter_caption', $enabled_filters), ], ], 'settings' => [ 'html_input' => 'allow', 'max_nesting_level' => 0, ], 'extensions' => [ // Footnotes were supported by default in the D7 version. [ 'id' => 'commonmark-footnotes', 'enabled' => TRUE, 'weight' => 0, 'settings' => [ 'container_add_hr' => TRUE, ], ], ], 'override' => TRUE, ]; } } return $value; } } Loading
markdown.module +25 −0 Original line number Diff line number Diff line Loading @@ -129,6 +129,31 @@ function markdown_migration_plugins_alter(array &$migrations) { // Add mapping from filter_markdown to markdown for D7 migrations. $migration['process']['filters']['process']['id']['map']['filter_markdown'] = 'markdown'; // Copied from https://www.drupal.org/project/migmag. // @see \Drupal\migmag\Utility\MigMagMigrationUtility::getAssociativeMigrationProcess() $get_associative_migration_process = function($process_pipeline): array { if (is_string($process_pipeline)) { return [['plugin' => 'get', 'source' => $process_pipeline]]; } elseif (array_key_exists('plugin', $process_pipeline)) { $process_pipeline = [$process_pipeline]; } return $process_pipeline; }; // We have to generate settings for the markdown filter. $filter_plugin_settings_processes = $get_associative_migration_process($migrations['d7_filter_format']['process']['filters']['process']['settings']); $filter_plugin_settings_processes[] = [ 'plugin' => 'markdown_settings_generator', ]; $migrations['d7_filter_format']['process']['filters']['process']['settings'] = $filter_plugin_settings_processes; // markdown_settings_generator needs to know the other filters that // enabled in order to generate valid settings. $migrations['d7_filter_format']['process']['filters']['include_source'] = TRUE; $migrations['d7_filter_format']['process']['filters']['source_key'] = 'source_format'; } } Loading
src/Plugin/migrate/process/MarkdownSettingsGenerator.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?php namespace Drupal\markdown\Plugin\migrate\process; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * @MigrateProcessPlugin( * id = "markdown_settings_generator", * handle_multiples = TRUE * ) */ class MarkdownSettingsGenerator extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if ($row->getDestinationProperty('id') === 'markdown') { $parser_manager = \Drupal::service('plugin.manager.markdown.parser'); // The markdown module during installation will automatically detect the // available parsers and select a default. // @see markdown_requirements() // @todo Add support for generating valid configuration for other parsers? if ($parser_manager->getDefaultParser()->getPluginId() === 'commonmark') { // @see markdown_migration_plugins_alter() $source_format = $row->getSourceProperty('source_format'); $enabled_filters = array_column($source_format['filters'], 'name'); $value = [ 'id' => 'commonmark', 'enabled' => TRUE, 'render_strategy' => [ 'type' => 'filter_output', 'custom_allowed_html' => '', 'plugins' => [ 'commonmark' => TRUE, // Footnotes were supported by default in the D7 version. 'commonmark-footnotes' => TRUE, // Enable Markdown support for specific filters if the filters are // enabled. 'filter_align' => in_array('filter_align', $enabled_filters), 'filter_caption' => in_array('filter_caption', $enabled_filters), 'media_embed' => in_array('filter_caption', $enabled_filters), ], ], 'settings' => [ 'html_input' => 'allow', 'max_nesting_level' => 0, ], 'extensions' => [ // Footnotes were supported by default in the D7 version. [ 'id' => 'commonmark-footnotes', 'enabled' => TRUE, 'weight' => 0, 'settings' => [ 'container_add_hr' => TRUE, ], ], ], 'override' => TRUE, ]; } } return $value; } }