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.
Basically, we need to provide a MigrateFieldHandler so that users can import link fields with the migrate module in it's 6.x-2.x branch. I made a blog post here: http://www.jcfiala.net/blog/2010/12/30/migratefieldhandler-link-module
Comments
Comment #1
quartsize CreditAttribution: quartsize commentedI'm looking into this, at the moment, on 7.
Comment #2
quartsize CreditAttribution: quartsize commentedHere's a patch for 7.x. I imagine the version for 6 wouldn't be a whole lot different, so it seemed wasteful to start a different issue.
Comment #3
Ramandeep_Kaur CreditAttribution: Ramandeep_Kaur commentedHow should we use this patch to migrate a link field
Comment #4
Ramandeep_Kaur CreditAttribution: Ramandeep_Kaur commentedThis patch worked fine. The version for the migrate module is 7.x-2.1 and the version for the link module is 7.x-1.0-alpha3.
We need to add the following line in our migration script to migrate links in drupal 7
$arguments = MigrateLinkFieldHandler::arguments(array('source_field' => 'link_name'));
$this->addFieldMapping('field_link', 'link_url')
->arguments($arguments);
Comment #5
mikeryanSubscribe (I'll update the Migrate Extras project page when this is committed).
Comment #6
abeger CreditAttribution: abeger commentedHas anyone migrated multiple links for a single field, each with their own titles? I'm currently attempting to hack together a couple different solutions, but I'd love it if someone has already done the work for me.
UPDATE: I've posted more of my situation over in a Migrate issue, here.
Comment #7
Bevan CreditAttribution: Bevan commentedThis version of the patch has been re-rolled to apply to 6.x-2.9. However it needs to be rerolled for 6.x-2.x-dev.
Comment #8
Bevan CreditAttribution: Bevan commentedOops! That was the patch from #2. this patch is for 6.x-2.9.
Comment #9
Bevan CreditAttribution: Bevan commentedI think I must have been confused above and meant 7.x-dev.
This version of the patch adds the ability for multiple URLs to be set AND for there to be a unique title per URL. The title source should be an array. E.g.
Allowing the title field to be an array is a bit of a hack since it requires use of
->prepareRow
to create the array. I have suggested what could be a better, cleaner and simpler solution as a feature request for the Migrate API: #1222668: Can I add onto a unlimited-value node reference field when updating?.Comment #10
eporama CreditAttribution: eporama commentedIn case anyone else needs it, I have created a patch for link-6.x-2.x that has the same functionality as #2.
This has no enhancements over #2, but just a backport to 6.x.
I didn't backport the patch from #9 because that didn't seem to be solved or agreed upon as a good solution with this issue and #1222668: Can I add onto a unlimited-value node reference field when updating?.
Comment #11
Bevan CreditAttribution: Bevan commented@eporama: Nice one. Thanks!
Comment #12
webdrips CreditAttribution: webdrips commented@eporama Thanks a bunch for the patch! It works quite nicely, but I'm having one minor issue: If a link source is empty, but a static title is set, when the data is imported, the link field will no longer be empty (versus saving a node with an empty link field in which case the link field is truly empty). Hopefully that was clear as mud.
I'm still trying to fully understand the Migrate module/process, so I'm not sure where/how to handle this issue. Any pointers would be greatly appreciated. (I can fix this at the theme level, but I'd have to do this for all my links, which is not desirable if another workaround exists.)
Is there any way to check if the url is empty() for the import data, and if so, don't import the filed for that particular node?
Thanks,
Dan
Comment #13
eporama CreditAttribution: eporama commented@daneesia, I tested the process with a static title and it behaved as I expected. It left NULL link sources and didn't assign them titles. Are you trying to import the static title? If you have that set on your cck field, you shouldn't need to set the title attribute in the migrate class.
If you addFieldMapping for the link field, but don't apply the title attribute in the class, you should get the desired behavior.
Comment #14
digitalcarla CreditAttribution: digitalcarla commentedThe patch from #2 doesn't apply when using Link module 7.x-1.0-alpha3.
The error is "error: patch failed: link.module:896". The link.module file from 1.0-alpha3 doesn't go up to line 896, and so the git apply command fails.
Any chance someone could reroll this patch for 7.x-1.0-alpha3?
Thanks!
Comment #15
Vacilando CreditAttribution: Vacilando commentedSubscribing.
Comment #16
dqd@ digitalcarla and all others
Please use latest --dev of link module from now. It is strongly recommended to use it rather than alpha3, since in the latest --dev push are already some of known issues fixed (html tags f.e. with static title, etc) and please go from there to report back for better overview and any leftovers.
Any reports and patches are much much appreciated in the moment, since we have still a lot to catch up to get right for final D7 release. I am appointed in here since yesterday to push things forward -
more info here: #1269718: Blockers to a 7.x-1.0 release?
Comment #17
Bevan CreditAttribution: Bevan commentedPerhaps it is time for another alpha release then? Or a beta?
Comment #18
dqdexactly. beta is in plan 4 next days. as I sad somewhere else in the queue, we will put some of the most important patches together to get away from the latest dev + patches. and to get feedback for final release schedule.
Comment #19
dqdbeta is out. :) 2 night shifts ... goto go sleepin ...
please start again with retrieving the patch for beta1 and a new issue! Would be much appreciated!
thanks for all contribution til here!
Comment #20
das-peter CreditAttribution: das-peter commentedOne point I'd like to mention is that the title should be importable as well. While attributes could be treated as equal for all items a title is directly related to an url.
Thus I wrote earlier this spring the attached migration handler.
This handler requires a joined string that contains the url and the title for a link. Thus it let's you define the separator to split the joined string and define which value is the title and which the url.
Another approach could be to implement
MigrateLinkFieldHandler->fields()
to provide a dedicated field which holds the link title.MigrateLinkFieldHandler->prepare()
joins then the values of the mapped url field and the special link title field.Comment #22
smithmilner CreditAttribution: smithmilner commentedRerolled #9 to work with drush make
Comment #23
alanburke CreditAttribution: alanburke commentedThis patch never got added as far as I can see.
Comment #24
dqdpatch fails ...
INFO: patch will be committed immediately when it passes without errors.
thanks for your effort. Awesome contribution!
Comment #25
eporama CreditAttribution: eporama commentedHere's a reroll of the patch in #21 to make it apply cleanly. The patch was just missing the git a/ b/ so git apply -p0 worked fine. This patch applied cleanly with git apply.
Comment #26
dqdcommitted to latest --dev
@ all: Awesome contribution! ROCK!
Comment #27
dqdDear contributers and patchers: please help us and take a look into one of our other main trouble makers:
#1319520: Gathered: Internationalized domain names (punycode)
#1295160: Gathered: options and tools to create Digg like site with link module
#1318938: An all-embracing attempt for URL validation and Input / Output Form Filtering
#1325112: Gathered: Integration of Link module working with Views module (6.x and 7.x)
Comment #28
eporama CreditAttribution: eporama commentedwoo hoo.
Any chance we can get the patch from #10 http://drupal.org/node/1010850#comment-4912598 into 6.x? ;-) Do you want a diff issue for that?
Comment #29
dqdSince most of the discussion run here, I think its ok to point to here for that. Let me check if the patch still fits to latest --dev
Comment #30
dqdcommitted to latest 6.x-2.x-dev
@ all: Awesome contribution! Please take a look into one of our other main trouble makers too:
#1319520: Gathered: Internationalized domain names (punycode)
#1295160: Gathered: options and tools to create Digg like site with link module
#1318938: An all-embracing attempt for URL validation and Input / Output Form Filtering
#1325112: Gathered: Integration of Link module working with Views module (6.x and 7.x)
Comment #31
Bevan CreditAttribution: Bevan commentedWoohoo!
Comment #33
elBradford CreditAttribution: elBradford commented@Bevan (or anyone)
I am trying to migrate links with unlimited values. Your example doesn't address migrating unlimited titles, just a very specific case. In mine only one of the links imports. I've been trying for days to get this to work. Here's my code related to the links:
Any advice on how to do this? The migrate documentation is good but it doesn't expose the api, at least I haven't found that. I really hope someone can guide me a little, thank you in advance.
Bradford
Comment #34
Bevan CreditAttribution: Bevan commentedIt was a while ago that I worked on this. I seem to remember that being a really really difficult problem to attempt to solve given Migrate's API (my problem wasn't quite that complicated). And that Migrate's hook that cleans up each "row" just after mapping but before inserting in Drupal was the only place you could build complicated multi-valued field values from flat & non-SQL sources (such as CSV). Sorry. :(
Comment #35
webdrips CreditAttribution: webdrips commentedHi @elBradford, did you ever figure out how to handle multiple link titles? Seems to me if the argument handling code could somehow be adjusted to handle an array, I think I have the rest solved.
Comment #36
elBradford CreditAttribution: elBradford commented@webdrips For the moment I'm focusing on other parts of migrating my site to drupal 7 - kind of letting this one sit for a bit. But I will probably return to this one in the next couple weeks.
Comment #37
webdrips CreditAttribution: webdrips commentedSeems like it's been solved for filefield, but I admit I haven't tried it just yet: http://drupal.org/node/1005090
Comment #38
webdrips CreditAttribution: webdrips commentedI was wrong about how filefield handles it; now it's much easier and cleaner using JSON.
Here is how I got multiple files/titles/descriptions added:
In my constructor:
In Prepare Row, do this:
I can probably look at creating a patch that applies similar logic to links, but I won't be able to get to it for several weeks.
Comment #39
pixlkat CreditAttribution: pixlkat commentedI came across this issue when I was trying to figure out how to migrate some data that had multiple links per node, each with their own title. I used the code from #9 as a starter, but discovered that didn't really work for me. Here's what I did in my prepareRow() (I queried a resources table which contained both file and url resources, so I attached them to the appropriate destination fields)
I couldn't figure out how to keep an empty record being created when there were no links associated with a node, but that is for another issue.
Comment #40
elBradford CreditAttribution: elBradford commentedThis was a pain to get working but I learned more about Migrate in the process. This is my code:
In the constructor I have the following:
"titles" and "links" are defined in prepareRow shown here:
The thing that confused me was that I didn't know that prepareRow can set up a new source, in my case "links" and "titles", so I can feed those arrays right into MigrateLinkFieldHandler.
Hopefully this can help someone who was as stuck as I was.
Comment #41
jsagotsky CreditAttribution: jsagotsky commentedMigrate 2.4 changed how it handles field arguments. Instead of using ->arguments you can map subfields. So link, link:title, and link:attributes would all show up in the destination field list.
To make that happen, link's field handler needs to implement fields(), which returns an associative array of field => description. I've attached mine, although I'm sure some of you will provide more interesting descriptions.
Comment #42
jpklein CreditAttribution: jpklein commentedFollowing up from #41, here's a complete patch for Migrate v2.4 that can be applied to the 7.x-1.0 release of Link.
Comment #43
Les LimChanging status.
Comment #44
jcfiala CreditAttribution: jcfiala commentedI'm not familiar with how migrate works - can someone take a look or give this a try?
Comment #45
Jelle_S#42 did not apply, new patch attached.
Comment #46
jaymallison CreditAttribution: jaymallison commentedPatch from #42 with #45 blended in worked great for me today for migrating in data on migrate 2.4-dev. Thanks guys! This should get committed into the project, very very helpful.
Comment #47
elstudio CreditAttribution: elstudio commentedAnd here's a clean patch for the combination of #42 and #45. Applies against Link 7.x-1.0. Works for me with migrate 7.x-2.4.
Thanks jpklein and Jelle_S.
Comment #48
Jelle_S@elstudio: patches should be made against latest dev ;-)
Comment #49
eporama CreditAttribution: eporama commentedThe patch in #45 does apply cleanly to dev 7.x-1.x.
The comments here about multiple URLs and titles are probably best held in #1222668: Can I add onto a unlimited-value node reference field when updating?.
I have tested this patch and it works fine.
Comment #50
eporama CreditAttribution: eporama commentedThe patch in #45 does apply cleanly to dev 7.x-1.x.
The comments here about multiple URLs and titles are probably best held in #1222668: Can I add onto a unlimited-value node reference field when updating?.
I have tested this patch and it works fine.
Comment #51
torgosPizzaI can confirm that the patch in #47 applies to Link 7.x-1.0 just fine, and after adding the new migrate.inc and clearing my site's Drupal cache, I'm able to successfully migrate D6 Link fields into D7.
Thanks a million!
Comment #52
burningdog CreditAttribution: burningdog commentedI've just used the 7.x-1.x-dev version of Link to migrate a link field from drupal 6 to drupal 7. Both of the following code snippets worked to migrate a link field that only had a URL in it (field_website_link is the source field, field_link is the destination field):
or
The migration also worked when applying the patch at #47 to Link 7.x-1.0
Comment #53
chingis CreditAttribution: chingis commentedPatch #45 doesn't consider if URL is NULL and we always have empty record in link field.
Fixed patch attached.
Comment #54
mikeryanRerolled against current -dev.
Comment #55
burningdog CreditAttribution: burningdog commentedUsing #54 the NULL links don't come across any more (normal links still work fine). Patch looks good to me!
If you've already been migrating links and have a bunch of NULL links in your database, you can get rid of them with a manual query (assuming your destination link field is called "field_link"):
Comment #56
jantoine CreditAttribution: jantoine commentedRe-rolled the patch fixing the implementation of the MigrateFieldHandler::fields() function for Migrate 7.x-2.5.
Comment #57
mikeryanThis patch consolidates the previous patch with patches from #1832754: Class registration for Migrate 2.5 or later and #1715378: Document available subfields in migration support (there were a couple different takes on fields() among them).
Comment #58
benjifisher@mikeryan:
As usual, you are a few steps ahead of me. I applied the patch from #57 and my links get pulled in like magic. Thanks!
Comment #59
jcfiala CreditAttribution: jcfiala commentedWell, I don't have time to test this so... Accepted!
Comment #61
jsagotsky CreditAttribution: jsagotsky commentedRerolled #56's patch for ff518b60113f29885a8f358e8b0fa4499b0c608d