Loading migrations/d7_pathauto_patterns.yml 0 → 100644 +23 −0 Changes for migrations/d7_pathauto_patterns.yml: 23 added lines, 0 removed lines. Original line number Diff line number Diff line id: d7_pathauto_patterns label: Pathauto patterns migration_tags: - Drupal 7 - Configuration source: plugin: pathauto_pattern constants: status: true selection_logic: 'and' process: status: constants/status id: id label: label type: type pattern: pattern selection_criteria: selection_criteria selection_logic: constants/selection_logic destination: plugin: 'entity:pathauto_pattern' migration_dependencies: optional: - d7_node_type migrations/d7_pathauto_settings.yml 0 → 100644 +95 −0 Changes for migrations/d7_pathauto_settings.yml: 95 added lines, 0 removed lines. Original line number Diff line number Diff line id: d7_pathauto_settings label: Pathauto configuration migration_tags: - Drupal 7 - Configuration source: plugin: variable variables: - pathauto_punctuation_ampersand - pathauto_punctuation_asterisk - pathauto_punctuation_at - pathauto_punctuation_backtick - pathauto_punctuation_back_slash - pathauto_punctuation_caret - pathauto_punctuation_colon - pathauto_punctuation_comma - pathauto_punctuation_dollar - pathauto_punctuation_double_quotes - pathauto_punctuation_equal - pathauto_punctuation_exclamation - pathauto_punctuation_greater_than - pathauto_punctuation_hash - pathauto_punctuation_hyphen - pathauto_punctuation_left_curly - pathauto_punctuation_left_parenthesis - pathauto_punctuation_left_square - pathauto_punctuation_less_than - pathauto_punctuation_percent - pathauto_punctuation_period - pathauto_punctuation_pipe - pathauto_punctuation_plus - pathauto_punctuation_question_mark - pathauto_punctuation_quotes - pathauto_punctuation_right_curly - pathauto_punctuation_right_parenthesis - pathauto_punctuation_right_square - pathauto_punctuation_semicolon - pathauto_punctuation_slash - pathauto_punctuation_tilde - pathauto_punctuation_underscore - pathauto_verbose - pathauto_separator - pathauto_max_length - pathauto_max_component_length - pathauto_transliterate - pathauto_reduce_ascii - pathauto_ignore_words - pathauto_case - pathauto_update_action source_module: pathauto process: punctuation/ampersand: pathauto_punctuation_ampersand punctuation/asterisk: pathauto_punctuation_asterisk punctuation/at: pathauto_punctuation_at punctuation/backtick: pathauto_punctuation_backtick punctuation/back_slash: pathauto_punctuation_back_slash punctuation/caret: pathauto_punctuation_caret punctuation/colon: pathauto_punctuation_colon punctuation/comma: pathauto_punctuation_comma punctuation/dollar: pathauto_punctuation_dollar punctuation/double_quotes: pathauto_punctuation_double_quotes punctuation/equal: pathauto_punctuation_equal punctuation/exclamation: pathauto_punctuation_exclamation punctuation/greater_than: pathauto_punctuation_greater_than punctuation/hash: pathauto_punctuation_hash punctuation/hyphen: pathauto_punctuation_hyphen punctuation/left_curly: pathauto_punctuation_left_curly punctuation/left_parenthesis: pathauto_punctuation_left_parenthesis punctuation/left_square: pathauto_punctuation_left_square punctuation/less_than: pathauto_punctuation_less_than punctuation/percent: pathauto_punctuation_percent punctuation/period: pathauto_punctuation_period punctuation/pipe: pathauto_punctuation_pipe punctuation/plus: pathauto_punctuation_plus punctuation/question_mark: pathauto_punctuation_question_mark punctuation/quotes: pathauto_punctuation_quotes punctuation/right_curly: pathauto_punctuation_right_curly punctuation/right_parenthesis: pathauto_punctuation_right_parenthesis punctuation/right_square: pathauto_punctuation_right_square punctuation/semicolon: pathauto_punctuation_semicolon punctuation/slash: pathauto_punctuation_slash punctuation/tilde: pathauto_punctuation_tilde punctuation/underscore: pathauto_punctuation_underscore verbose: pathauto_verbose separator: pathauto_separator max_length: pathauto_max_length max_component_length: pathauto_max_component_length transliterate: pathauto_transliterate reduce_ascii: pathauto_reduce_ascii ignore_words: pathauto_ignore_words case: pathauto_case update_action: pathauto_update_action destination: plugin: config config_name: pathauto.settings src/Plugin/migrate/source/PathautoPattern.php 0 → 100644 +133 −0 Changes for src/Plugin/migrate/source/PathautoPattern.php: 133 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\pathauto\Plugin\migrate\source; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Fetches pathauto patterns from the source database. * * @MigrateSource( * id = "pathauto_pattern", * source_module = "pathauto", * ) */ class PathautoPattern extends DrupalSqlBase { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager); $this->entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { return new static( $configuration, $plugin_id, $plugin_definition, $migration, $container->get('state'), $container->get('entity.manager'), $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ public function query() { // Fetch all pattern variables whose value is not a serialized empty string. return $this->select('variable', 'v') ->fields('v', ['name', 'value']) ->condition('name', 'pathauto_%_pattern', 'LIKE') ->condition('value', 's:0:"";', '<>'); } /** * {@inheritdoc} */ public function getIds() { $ids['name']['type'] = 'string'; return $ids; } /** * {@inheritdoc} */ public function fields() { return [ 'name' => $this->t("The name of the pattern's variable."), 'value' => $this->t("The value of the pattern's variable."), ]; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { $entity_definitions = $this->entityTypeManager->getDefinitions(); $name = $row->getSourceProperty('name'); // Pattern variables are made of pathauto_[entity type]_[bundle]_pattern. // First let's find a matching entity type from the variable name. foreach ($entity_definitions as $entity_type => $definition) { // Check if this is the default pattern for this entity type. // Otherwise, check if this is a pattern for a specific bundle. if ($name == 'pathauto_' . $entity_type . '_pattern') { // Set process values. $row->setSourceProperty('id', $entity_type); $row->setSourceProperty('label', (string) $definition->getLabel() . ' - default'); $row->setSourceProperty('type', 'canonical_entities:' . $entity_type); $row->setSourceProperty('pattern', unserialize($row->getSourceProperty('value'))); return parent::prepareRow($row); } elseif (strpos($name, 'pathauto_' . $entity_type . '_') === 0) { // Extract the bundle out of the variable name. preg_match('/^pathauto_' . $entity_type . '_([a-zA-z0-9_]+)_pattern$/', $name, $matches); $bundle = $matches[1]; // Check that the bundle exists. $bundles = $this->entityManager->getBundleInfo($entity_type); if (!in_array($bundle, array_keys($bundles))) { // No matching bundle found in destination. return FALSE; } // Set process values. $row->setSourceProperty('id', $entity_type . '_' . $bundle); $row->setSourceProperty('label', (string) $definition->getLabel() . ' - ' . $bundles[$bundle]['label']); $row->setSourceProperty('type', 'canonical_entities:' . $entity_type); $row->setSourceProperty('pattern', unserialize($row->getSourceProperty('value'))); $selection_criteria = [ 'id' => ($entity_type == 'node') ? 'node_type' : 'entity_bundle:' . $entity_type, 'bundles' => [$bundle => $bundle], 'negate' => FALSE, 'context_mapping' => [$entity_type => $entity_type], ]; $row->setSourceProperty('selection_criteria', [$selection_criteria]); return parent::prepareRow($row); } } return FALSE; } } Loading
migrations/d7_pathauto_patterns.yml 0 → 100644 +23 −0 Changes for migrations/d7_pathauto_patterns.yml: 23 added lines, 0 removed lines. Original line number Diff line number Diff line id: d7_pathauto_patterns label: Pathauto patterns migration_tags: - Drupal 7 - Configuration source: plugin: pathauto_pattern constants: status: true selection_logic: 'and' process: status: constants/status id: id label: label type: type pattern: pattern selection_criteria: selection_criteria selection_logic: constants/selection_logic destination: plugin: 'entity:pathauto_pattern' migration_dependencies: optional: - d7_node_type
migrations/d7_pathauto_settings.yml 0 → 100644 +95 −0 Changes for migrations/d7_pathauto_settings.yml: 95 added lines, 0 removed lines. Original line number Diff line number Diff line id: d7_pathauto_settings label: Pathauto configuration migration_tags: - Drupal 7 - Configuration source: plugin: variable variables: - pathauto_punctuation_ampersand - pathauto_punctuation_asterisk - pathauto_punctuation_at - pathauto_punctuation_backtick - pathauto_punctuation_back_slash - pathauto_punctuation_caret - pathauto_punctuation_colon - pathauto_punctuation_comma - pathauto_punctuation_dollar - pathauto_punctuation_double_quotes - pathauto_punctuation_equal - pathauto_punctuation_exclamation - pathauto_punctuation_greater_than - pathauto_punctuation_hash - pathauto_punctuation_hyphen - pathauto_punctuation_left_curly - pathauto_punctuation_left_parenthesis - pathauto_punctuation_left_square - pathauto_punctuation_less_than - pathauto_punctuation_percent - pathauto_punctuation_period - pathauto_punctuation_pipe - pathauto_punctuation_plus - pathauto_punctuation_question_mark - pathauto_punctuation_quotes - pathauto_punctuation_right_curly - pathauto_punctuation_right_parenthesis - pathauto_punctuation_right_square - pathauto_punctuation_semicolon - pathauto_punctuation_slash - pathauto_punctuation_tilde - pathauto_punctuation_underscore - pathauto_verbose - pathauto_separator - pathauto_max_length - pathauto_max_component_length - pathauto_transliterate - pathauto_reduce_ascii - pathauto_ignore_words - pathauto_case - pathauto_update_action source_module: pathauto process: punctuation/ampersand: pathauto_punctuation_ampersand punctuation/asterisk: pathauto_punctuation_asterisk punctuation/at: pathauto_punctuation_at punctuation/backtick: pathauto_punctuation_backtick punctuation/back_slash: pathauto_punctuation_back_slash punctuation/caret: pathauto_punctuation_caret punctuation/colon: pathauto_punctuation_colon punctuation/comma: pathauto_punctuation_comma punctuation/dollar: pathauto_punctuation_dollar punctuation/double_quotes: pathauto_punctuation_double_quotes punctuation/equal: pathauto_punctuation_equal punctuation/exclamation: pathauto_punctuation_exclamation punctuation/greater_than: pathauto_punctuation_greater_than punctuation/hash: pathauto_punctuation_hash punctuation/hyphen: pathauto_punctuation_hyphen punctuation/left_curly: pathauto_punctuation_left_curly punctuation/left_parenthesis: pathauto_punctuation_left_parenthesis punctuation/left_square: pathauto_punctuation_left_square punctuation/less_than: pathauto_punctuation_less_than punctuation/percent: pathauto_punctuation_percent punctuation/period: pathauto_punctuation_period punctuation/pipe: pathauto_punctuation_pipe punctuation/plus: pathauto_punctuation_plus punctuation/question_mark: pathauto_punctuation_question_mark punctuation/quotes: pathauto_punctuation_quotes punctuation/right_curly: pathauto_punctuation_right_curly punctuation/right_parenthesis: pathauto_punctuation_right_parenthesis punctuation/right_square: pathauto_punctuation_right_square punctuation/semicolon: pathauto_punctuation_semicolon punctuation/slash: pathauto_punctuation_slash punctuation/tilde: pathauto_punctuation_tilde punctuation/underscore: pathauto_punctuation_underscore verbose: pathauto_verbose separator: pathauto_separator max_length: pathauto_max_length max_component_length: pathauto_max_component_length transliterate: pathauto_transliterate reduce_ascii: pathauto_reduce_ascii ignore_words: pathauto_ignore_words case: pathauto_case update_action: pathauto_update_action destination: plugin: config config_name: pathauto.settings
src/Plugin/migrate/source/PathautoPattern.php 0 → 100644 +133 −0 Changes for src/Plugin/migrate/source/PathautoPattern.php: 133 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Drupal\pathauto\Plugin\migrate\source; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Fetches pathauto patterns from the source database. * * @MigrateSource( * id = "pathauto_pattern", * source_module = "pathauto", * ) */ class PathautoPattern extends DrupalSqlBase { /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager); $this->entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { return new static( $configuration, $plugin_id, $plugin_definition, $migration, $container->get('state'), $container->get('entity.manager'), $container->get('entity_type.manager') ); } /** * {@inheritdoc} */ public function query() { // Fetch all pattern variables whose value is not a serialized empty string. return $this->select('variable', 'v') ->fields('v', ['name', 'value']) ->condition('name', 'pathauto_%_pattern', 'LIKE') ->condition('value', 's:0:"";', '<>'); } /** * {@inheritdoc} */ public function getIds() { $ids['name']['type'] = 'string'; return $ids; } /** * {@inheritdoc} */ public function fields() { return [ 'name' => $this->t("The name of the pattern's variable."), 'value' => $this->t("The value of the pattern's variable."), ]; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { $entity_definitions = $this->entityTypeManager->getDefinitions(); $name = $row->getSourceProperty('name'); // Pattern variables are made of pathauto_[entity type]_[bundle]_pattern. // First let's find a matching entity type from the variable name. foreach ($entity_definitions as $entity_type => $definition) { // Check if this is the default pattern for this entity type. // Otherwise, check if this is a pattern for a specific bundle. if ($name == 'pathauto_' . $entity_type . '_pattern') { // Set process values. $row->setSourceProperty('id', $entity_type); $row->setSourceProperty('label', (string) $definition->getLabel() . ' - default'); $row->setSourceProperty('type', 'canonical_entities:' . $entity_type); $row->setSourceProperty('pattern', unserialize($row->getSourceProperty('value'))); return parent::prepareRow($row); } elseif (strpos($name, 'pathauto_' . $entity_type . '_') === 0) { // Extract the bundle out of the variable name. preg_match('/^pathauto_' . $entity_type . '_([a-zA-z0-9_]+)_pattern$/', $name, $matches); $bundle = $matches[1]; // Check that the bundle exists. $bundles = $this->entityManager->getBundleInfo($entity_type); if (!in_array($bundle, array_keys($bundles))) { // No matching bundle found in destination. return FALSE; } // Set process values. $row->setSourceProperty('id', $entity_type . '_' . $bundle); $row->setSourceProperty('label', (string) $definition->getLabel() . ' - ' . $bundles[$bundle]['label']); $row->setSourceProperty('type', 'canonical_entities:' . $entity_type); $row->setSourceProperty('pattern', unserialize($row->getSourceProperty('value'))); $selection_criteria = [ 'id' => ($entity_type == 'node') ? 'node_type' : 'entity_bundle:' . $entity_type, 'bundles' => [$bundle => $bundle], 'negate' => FALSE, 'context_mapping' => [$entity_type => $entity_type], ]; $row->setSourceProperty('selection_criteria', [$selection_criteria]); return parent::prepareRow($row); } } return FALSE; } }