diff --git a/link.migrate.inc b/link.migrate.inc new file mode 100644 index 0000000..f5d9b44 --- /dev/null +++ b/link.migrate.inc @@ -0,0 +1,85 @@ +addFieldMapping('field_link', 'url'); + * + * // Import source field "url" containing an URL into + * // destination field: field_link, using + * // source field "url_title" as the title: + * $arguments = MigrateLinkFieldHandler::arguments(array('source_field' => 'url_title')); + * $this->addFieldMapping('field_link', 'url') + * ->arguments($arguments); + * + * // Import source field "url" containing an URL into + * // destination field: field_link, using + * // the static string: "View Details" as the title: + * $arguments = MigrateLinkFieldHandler::arguments('View Details'); + * $this->addFieldMapping('field_link', 'url') + * ->arguments($arguments); + */ + +/** + * Field handler. + */ +class MigrateLinkFieldHandler extends MigrateFieldHandler { + public function __construct() { + $this->registerTypes(array('link_field')); + } + + static function arguments($title = NULL) { + $arguments = array(); + if (!is_null($title)) { + $arguments['title'] = $title; + } + return $arguments; + } + + public function prepare(stdClass $entity, array $field_info, array $instance, array $values) { + if (isset($values['arguments'])) { + $arguments = $values['arguments']; + unset($values['arguments']); + } + else { + $arguments = array(); + } + + $migration = Migration::currentMigration(); + $destination = $migration->getDestination(); + $language = $this->getFieldLanguage($entity, $field_info, $arguments); + + // Setup the standard Field API array for saving. + $delta = 0; + foreach ($values as $value) { + $item = array(); + if (isset($arguments['title'])) { + $item['title'] = $arguments['title']; + } + $item['url'] = $value; // save the main field mapping in the URL field + // Links do not have a "value", so no: $item['value'] = $value; + + $return[$language][$delta] = $item; + $delta++; + } + + return isset($return) ? $return : NULL; + } +} diff --git a/migrate_extras.info b/migrate_extras.info index 004f0ad..c778b7f 100644 --- a/migrate_extras.info +++ b/migrate_extras.info @@ -8,3 +8,5 @@ dependencies[] = migrate files[] = media.migrate.inc files[] = pathauto.migrate.inc files[] = rules.migrate.inc +files[] = link.migrate.inc +