For the Drupal 7 version, we should add a url.migrate.inc file that includes url_migrate_api() and a migration field handler for url fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Version: » 7.x-1.x-dev
hart0554’s picture

Here's a patch for basic Migrate field handler. Please forgive any newb mistakes.

Dave Reid’s picture

Status: Active » Needs work

@hart0554: Thank you very much for getting this started and providing a patch!

It looks like we'll want to declare this as a 'field handler' in url_migrate_api due to the recent changes in Migrate: https://drupal.org/node/1824884. The prepare callback seems much more complex than I had thought it would be. I'll double check if we can't do something simpler.

Dave Reid’s picture

Actually I think we don't even need to write our own Migration handler anymore with the recent 2.6 changes.

DrupalGideon’s picture

I'm not getting this to work fully with Migrate 2.6 RC1. I'm getting the URL part migrated across absolutely fine but the title doesn't work.

It wants to migrate to the following destination fields -

field_user_social_link	Social Link (url)
field_user_social_link:title	The title of the URL.
field_user_social_link:attributes	The serialized array of attributes of the URL.

I'm ignoring the 'attributes' as they seem to be blank but the title is not working.

I have my content type set to allow Unlimited values of URL links and I've passed single values, arrays, strings with a separator and all work for the URL part but not the title.

I can force a fixed value into the DB but not the migrated values. For now I think i'm going to have to do some extra processing in the prepare function to get the values into my new entity.

frega’s picture

Could not get migrate-7.x-2.6 to work out of the box. Rerolled patch from #2, moving url_migrate_api (hook_migrate_api) to the url.module file. Works for me w/ current stable (migrate-7.x-2.5).

frega’s picture

Status: Needs work » Needs review

Setting to needs review.

progpapa’s picture

Seems to be working for me out of the box with migrate-7.x-2.6.

This is the relevant part of the code:

$this->addFieldMapping('field_news_link', 'source_url');
$this->addFieldMapping('field_news_link:title', 'source_title');

Haven't tried with attributes, though.

jas1988’s picture

I have done migration from 7 to 8 and my content type is having url field. But this is missing in Drupal 8 content type after migration. Please suggest how to make possible to migrate url field of content type to 8. Thanks!

heddn’s picture

If the field doesn't just migrate on its own then you'll you need to create a custom field plugin for the url field type for D7. This should be added to a custom module that you create. See https://api.drupal.org/api/drupal/core!modules!link!src!Plugin!migrate!f... as an example of how this was done for the more mainstream link field.

jas1988’s picture

Thanks for reply! I am very new to custom migration for 7 to 8 of url field of this kind. It will be very helpful if you can link some documentation links (I tried to search lot but unable to find solution ) so that I can read and understand more to migrate data and revision data of this field . Please suggest !

heddn’s picture

jas1988’s picture

Thank you @heddn !! I am able to migrate url field data from 7 to 8 :

Plugin code used is below:

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;

/**
 * @MigrateField(
 * id = "url",
 * core = {7},
 * type_map = {
 * "url" = "link"
 * },
 * source_module = "url",
 * destination_module = "link"
 * )
 */
class url extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getFieldWidgetMap() {
    return [
      'url' => 'link',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldFormatterMap() {
    return [
      'default' => 'link',
      'url' => 'link',
      'url_external' => 'link',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
    $process = [
      'plugin' => 'sub_process',
      'source' => $field_name,
      'process' => [
        'uri' => 'value',
      ],
    ];
    $migration->setProcessOfProperty($field_name, $process);
  }

}
rafaticarte’s picture

Hi,

Where have I put the code plugin?

Thanks.

jas1988’s picture

Hi, you just need to place custom module having above plugin code. Change your field name etc (screenshot for details)