Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you need to modify data in the node body during the migration process, you can use prepareRow($row).
The following example displays how to call the user defined method "convertWiki2Html" which converts the node body from wiki markup to HTML:
// manipulate the source rows
public function prepareRow($current_row) {
$current_row->body = $this->convertWiki2Html($current_row->body_text,$current_row->page_title);
}
public function convertWiki2Html(&$body,&$title){
// convert $body from mediawiki to HTML here...
}
You can also add one or more callbacks when adding field mappings, like in this example from wine.inc (part of the migrate_example module) that adds two callbacks to the body field:
// TIP: You can apply one or more functions to a source value using
// ->callbacks(). The function must take a single argument and return a
// value which is a transformation of the argument. As this example shows,
// you can have multiple callbacks, and they can either be straight
// functions or class methods. In this case, our custom method prepends
// 'review: ' to the body, and then we call a standard Drupal function to
// uppercase the whole body.
$this->addFieldMapping('body', 'body')
->callbacks(array($this, 'addTitlePrefix'), 'drupal_strtoupper');