Can anyone advice me on how to programmatically create multiple url aliases for each row of a migration?

I am using the Migrate module to migrate page content into Drupal from an XML document.

The existing system has multiple url alias data for each page and I need that same information represented in Drupal - which is proving to be challenging.

I tried doing the following in the complete function of my custom migrate class:

function complete($entity, $row) {
    // drush_print_r($entity);
    // Create an object with our redirect parameters
    $redirect = new stdClass();
    $redirect->source = "node/{$entity->nid}";     // From URL
    $redirect->source_options = array();
    $redirect->redirect = 'http://www.google.com';        // To URL
    $redirect->redirect_options = array();
    $redirect->status_code = 0;            // Redirect Status, 0 is default
    // $redirect->type = 'redirect';
    $redirect->language = LANGUAGE_NONE;
    // Create the redirect

 /****************** **I also tried the following** *******************/
    // $entity->path['alias'] = 'test/testing';

I then carryout a sample migration but my url redirects are not present in the node edit area.

Can anyone help, please?


If I understand correctly, based on your example, you'll need to switch the to and from URLs. If you want the new node to display the redirects in the node edit form, the node ID should be as follows:

$redirect->redirect = 'node/' . $node->nid;

FYI - programmatic redirect creation here.

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.