3

I am migrating a Drupal 6 site to Drupal 8. On the Drupal 6 site I have a content type called book_page but would like it be called faq on the new site.

I set the default_bundle to faq in my yml file but it still migrates as book_page.

Here is my yml file:

uuid: a67dbd6f-416c-44c0-9698-05ec3bb3c5a9
langcode: en
status: true
dependencies: {  }
id: upgrade_d6_node_book_page
migration_tags:
  - 'Drupal 6'
migration_group: d6_migrate_group
label: 'Nodes (book_page)'
source:
  plugin: d6_node
  node_type: book_page
process:
  nid: tnid
  vid: vid
  langcode:
    plugin: default_value
    source: language
    default_value: und
  title: title
  uid: node_uid
  status: status
  created: created
  changed: changed
  promote: promote
  sticky: sticky
  body/format:
    plugin: migration
    migration: upgrade_d6_filter_format
    source: format
  body/value: body
  body/summary: teaser
  revision_uid: revision_uid
  revision_log: log
  revision_timestamp: timestamp
  field_image:
    plugin: d6_cck_file
    source: field_image
  field_upload_files:
    plugin: d6_cck_file
    source: field_upload_files
destination:
  plugin: 'entity:node'
  default_bundle: faq
migration_dependencies:
  required:
    - upgrade_d6_user
    - upgrade_d6_node_type
    - upgrade_d6_node_settings
    - upgrade_d6_filter_format
  optional:
    - upgrade_d6_field_instance_widget_settings
    - upgrade_d6_field_formatter_settings
    - upgrade_d6_upload_field_instance

Anyone have an idea what I am doing wrong?

Update:

I have also tried adding the following under process under each of my node yml files?:

type:
  plugin: default_value
  value: faq

I wonder if the All node types are created in ....node_type.yml?

2 Answers 2

5

As you've figured out, modifying the d6_node-based migration affects how the content of a given node type is migrated, but does not affect how the actual node type itself is migrated - that is done in d6_node_type. To rename the types themselves in migration, while you could modify the source query as you did, it's simpler to modify the .yml to remap values. In upgrade_d6_node_type.yml, you can replace

process:
  type: type
  name: name

with

process:
  type:
    plugin: static_map
    bypass: true
    source: type
    map:
      story: post
      book_page: faq
  name:
    plugin: static_map
    bypass: true
    source: name
    map:
      story: post
      'Book Page': Faq
4
  • Thanks! That looks like a better way than I did. Any simple way to exclude content types as well from being created?
    – albertski
    Commented Sep 14, 2016 at 20:44
  • @albertski: Removing bypass: true from the type mapping should skip any node types not explicitly mapped.
    – Mike Ryan
    Commented Oct 14, 2016 at 22:46
  • @Pierre.Vriens - Afraid I've never been - maybe someday!
    – Mike Ryan
    Commented Oct 14, 2016 at 22:46
  • Does anyone know what the key "story" refers to? Is that something from the OP that isn't there anymore, or a Drupal thing? I don't see mentioned it anywhere on drupalmigrate.org/plugin/process/staticmap or the OP, so not sure where it came from and if I need it. Commented Oct 24, 2023 at 20:13
0

I was able to perform this by creating a custom module and adding a custom source plugin to modify the query.

custom_migration/src/Plugin/migrate/source/d6/CustomNodeType.php

<?php

namespace Drupal\custom_migration\Plugin\migrate\source\d6;

use Drupal\node\Plugin\migrate\source\d6\NodeType;

/**
 * Drupal 6 Node types source from database.
 *
 * @MigrateSource(
 *   id = "custom_node_type"
 * )
 */
class CustomNodeType extends NodeType {
  /**
   * Override the query() method, and provide a custom query that selects just
   * the node types you want.
   */
  public function query() {
    // Our custom query returns only the node types we want and renames them.
    $query = $this->select('node_type', 't');
    $query->fields('t', array(
        'module',
        'description',
        'help',
        'title_label',
        'has_body',
        'body_label',
        'min_word_count',
        'custom',
        'modified',
        'locked',
        'orig_type',
      ));

    // Rename content types.
    $query->addExpression("
      CASE
        WHEN t.type = 'story' THEN 'post'
        WHEN t.type = 'book_page' THEN 'faq'
        ELSE t.type
      END
    ", 'type');

    // Rename content type names.
    $query->addExpression("
      CASE
        WHEN t.name = 'Book Page' THEN 'Faq'
        WHEN t.name = 'Story' THEN 'Story'
        ELSE t.name
      END
    ", 'name');

    // Exclude content types you don't want to migrate.
    $query->condition('t.type', array('forum', 'program', 'show', 'webform', 'homepage_slide'), 'NOT IN');
    $query->orderBy('t.type');

    return $query;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.