Closed (fixed)
Project:
Term Level Field
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Jan 2013 at 16:32 UTC
Updated:
27 Feb 2013 at 15:10 UTC
Jump to comment: Most recent file
Comments
Comment #1
alexweber commentedInitial migrate field handler implementation attached.
There's some room for improvement such as making it behave like legit term reference handler (using SourceMigration to map tids) but either way its a solid start IMO.
Comment #2
alexweber commentedFixed a minor typo in the hook implementation
Comment #3
alexweber commentedOk so turns out that the above implementation actually works very well with single value fields however it falls short with fields that accept multiple values.
The reasoning is simple: We're using field mapper arguments for the level and the arguments are bound to the mapping in general and can't (that I know of) be specified dynamically. I even tried using ->separator(',') on both the primary value and arguments and passing a comma-separated string but the argument doesn't know how to deal with multiple values and implementing that turned out to be kinda messy.
So, plan B is actually even more elegant and I can confirm that it works like a charm on multi-value fields: use a subfield.
So here's a new patch that refactors the field handler implementation to use subfields instead of arguments for the term level.
Comment #4
mh86 commentedThanks for the patch, Alex!
I haven't tested it yet, and I'm not familiar with the internals of migrate field handlers, but this handler might soon be a topic for the Recruiter.
Do you have a code sample how the handler is used in migration scripts (e.g. in drop jobs)?
Comment #5
alexweber commented@mh86, why yes I do and thanks for asking! )
Lines 43-46: http://drupalcode.org/project/drop_jobs.git/blob/refs/heads/7.x-1.x:/modules/custom/drop_jobs_demo/drop_jobs_demo_candidates_skills.migrate.inc
BTW, the only reason I had to manually find the TID in prepareRow() is because the "skill" vocab terms were imported using Taxonomy CSV and not migrated using migrate, if that had been the case I could have just as easily gone with something like this:
I've successfully tested this handler with both single and multi-value Term Level fields and it seems to work 100%.
PS - In order to get these exported via CSV I had to create an extra field formatter for term_level fields to export in a CSV-friendly format (simple and particular enough use case that I didn't bother with a patch, let me know if this is interesting though)
Comment #6
alexweber commentedOops, the previous patch removed the newline at the end of term_level.info and caused some weird errors when installing a distribution that requires term_level.
This new patch just makes sure that the newline at the end of that file remains intact.
Comment #7
alexweber commentedI'm actually getting a bit embarrassed by the repeated patch posting that's going on over here. The patches in #3 and #6 apply cleanly (using git apply) and work fine locally but for whatever reason the Drupal.org build script is having trouble building my distribution with this patch. I'm using drush make with --working-copy to test it and I've read that sometimes it can cause patches to fail.
Regardless, here's my last-ditch attempt. I've started from a clean slate and generated a clean patch by staging the changes and doing git diff --cached, which I've now learnt is the preferred method to include new files in a patch.
Hope this works and if it doesn't, I promise I'll find another issue queue to flood.
Thank you for your patience!
Comment #8
mh86 commentedHi Alex,
thanks for your work, I've just committed your patch!
I haven't tried it with a concrete migrate example yet, but the code basically looks good. If there are any issues, we can handle it in follow-ups.
No idea why the patch didn't apply with drush, but we've seen such problems in the Recruiter as well.
Comment #9
alexweber commentedAwesome, thanks!!!
Comment #10
mh86 commentedHey Alex,
I've added a small extension to the migration handler, so that term names can be passed as well (we're using it in the Recruiter). The code is more or less copied from the default term field handler, and I hope it does not destroy your existing migrationa. If so you might have to change the source_type in the arguments.
Diff: http://drupalcode.org/project/term_level.git/commitdiff/1abc4cf
Comment #11
alexweber commentedHey Matthias, no worries, thanks for the heads up!
This is a nice improvement, I'll update my migrations to use it! :)