1

I am migrating content using both the migrate, migrate_d2d and my own custom module which references the 2 migrate modules. The below code successfully migrates content from Drupal 6 to Drupal 7 when registering and running the migration of "PressMigration" within the .module file but I always want the Drupal 7 migrated content body area to have the "Text format" of "Full HTML". How can I get all the migrated content to have the "Text format" of "Full HTML" for the body.

Thanks,

John

class PressMigration extends DrupalNode6Migration {

  protected function query() {
    $query = parent::query();
    //Only include specific nodes in migrationj
    $query->addJoin('LEFT OUTER', 'term_node', 'tn', 'n.vid=tn.vid');
    $query->addField('tn', 'tid', 'tn.tid');
    $query->addField('tn', 'vid', 'tn.vid');
    $query->condition('tn.tid', '115', '=');
    return $query;
  }

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('field_release_date', 'field_release_date');
    $this->addFieldMapping('field_contact', 'field_contact_information');

    $this->addFieldMapping('field_subtitle', 'field_sub_title');
    $this->addFieldMapping('field_teaser', 'field_media_excerpt');
    $this->addFieldMapping('field_custom_title', 'field_custom_title');

    $this->addFieldMapping('field_alt_lang', 'field_alternate_lang');
    $this->addFieldMapping('field_related_item', 'field_media_related');
    $this->addFieldMapping('field_archiving_date', 'field_archive_date');
  }

}
2
+100

When we migrated from Drupal 6 to Drupal 7 we used a format_mapping like this so that everything became filtered_html:

'format_mappings' => array(
               '1' => 'filtered_html', // Filtered HTML
               '2' => 'filtered_html', // PHP code
               '3' => 'filtered_html', // Full HTML
               ),

The comments above show the Drupal 6 names we had for the numeric format codes. format_mappings is an element of the arguments passed to the registerMigration() method, such as:

Migration::registerMigration('FooMigration', $arguments['machine_name'], $arguments);
2

You should try to set the input format on the body field in this way:

$this->addFieldMapping('body', 'body')
 ->arguments(array('format' => 'full_html'));
  • I already tried that and it did not work saying something like field already exists. – John Mitchell Jan 12 '14 at 23:11
  • Ok, this is caused by Migrate_d2d which already add the field mapping on the body. Probably you have to add your specific format mappings. On the migration class you can add an optional argument called "format_mappings": an array with the ID from the source and the ID for the destination. Example: 'format_mappings' => array('3', 'full_html')". – FiNeX Jan 13 '14 at 0:05
  • So "'format_mappings' => array('3', 'full_html')" should be in the same area as where I have my "$this->addFieldMapping" statements? – John Mitchell Jan 13 '14 at 13:01
  • @JohnMitchell : you've to add the 'format_mappings" on the arguments when you register the migration on function yourmodule_register_migration() in the $common_arguments array. – FiNeX Jan 13 '14 at 21:51
1

It is recommended to use the module Drupal-to-Drupal data migration: migrate_d2d.

There you can map your legacy filters to the destination filters, by passing a format_mappings argument when registering the node migration, as described in the issue Set text filter for migrations. Note that before Drupal 7 an integer value was used instead of machine names.

$arguments = array(
  'source_connection' => 'legacy',
  'source_version' => 6,
  'description' => t('Migration of core blog nodes from Drupal 6 to custom blog nodes'),
  'machine_name' => 'ExBlog',
  'source_type' => 'blog',
  'destination_type' => 'custom_blog_type',
  'user_migration' => 'ExUser',  // Machine name of our user migration above
  'format_mappings' => array(
    '1' => 'filtered_html',
    '2' => 'full_html',
    '3' => 'plain_text',
  ),
);
Migration::registerMigration('DrupalNode6Migration', $arguments['machine_name'], $arguments);
0

In the past I've succesfully used the abstract Node migration class (the first code block) here: https://drupal.org/node/1513766.

It assumes the default migration module (I didn't use migrate_d2d so I don't know about compatibility).

This part that matches the D6 numeric notation to the D7 string notation worked for me.

public function prepareRow($current_row) {
  $formats = array(
    '1' => 'filtered_html',
    '2' => 'full_html',
    '3' => 'plain_text',
    '4' => 'markdown',
  );
  $current_row->format = isset($formats[$current_row->format]) ? $formats[$current_row->format] : 'plain_text';
}

Since you want all nodes to be Full HTML, I'd say adding the following should work.

public function prepareRow($current_row) {
  $current_row->format = 'full_html';
}
0

This one worked for me for every field:

$node_options = MigrateDestinationNode::options(LANGUAGE_NONE, 'filtered_html');
$this->destination = new MigrateDestinationNode('node', $node_options);
0

The field mapping arguments() method is now deprecated - please use subfield notation instead.

-> You can also set the textformat for the whole destination:

$this->destination = new MigrateDestinationNode('lexiconentry',array('text_format' => 'full_html'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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