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.
Problem/Motivation
It's a common task to take source values and change them based on a configuration mapping.
Proposed resolution
Add this plugin. Documented in the handbook already.
Remaining tasks
Find a better name. Map? IdMap makes that confusing. lookup? MigrateIdMapInterface has lookupSourceId and lookupDestinationId and this isn't like them. I don't know a better name.
Comment | File | Size | Author |
---|---|---|---|
#10 | 2147817_6.patch | 3.76 KB | chx |
#10 | interdiff.txt | 1.95 KB | chx |
#3 | 2147817_3.patch | 3.68 KB | chx |
Comments
Comment #1
mikeryandreditor went a little funky on me, but the transform() method doesn't look right at all - it's returning the last translated value from the map, and if $value was empty it's going to return the whole configured map.
We need more tests - at least empty values, and values with no match in the map.
Is there any way to set options on the process plugin? Thinking case-sensitivity might be a useful switch to flip now and then...
As for naming... Yes, map is kind of overloaded, and my first instinct, translation table, would also cause confusion. Wikipedia seems to consider lookup table the canonical name for this sort of thing...
Comment #2
chx CreditAttribution: chx commentedI think static map will do. The plugin got exceptions and the test has been expanded to cover them. While at it, I have refactored the test to be slightly smaller.
Comment #3
chx CreditAttribution: chx commentedJust doxygen fixes for the test.
Comment #5
chx CreditAttribution: chx commented3: 2147817_3.patch queued for re-testing.
Drupal\system\Tests\Form\FormTest failed. I have nothing to do with that.
Comment #7
chx CreditAttribution: chx commented3: 2147817_3.patch queued for re-testing.
Comment #8
dawehnerAs always pointing to the tested code + @group Drupal would be cool
... just a side-note: setUP used to be protected, so we change the visibility technically here.
Comment #9
webchickchx and I were talking this through trying to come up with suitable docs for transform() (since @inheritdoc is useless on these) and he came to the realization that we could probably just use NestedArray here and move those exceptions there instead.
Also needs a @see to the extended docs in the handbook, and Daniel's @group thing. chx wasn't as sure about the visibility of setUp().
Comment #10
chx CreditAttribution: chx commentedI am not moving the exception but inlineing NestedArray::getValue is not helpful.
Comment #11
joelpittetBack to RTBC. Changes look great.
Comment #12
chx CreditAttribution: chx commentedI must add that this new code raises a new idea (obviously new issue): an
extract
plugin where the heart of the plugin is the same, just swap the $value and the $configuration:$new_value = NestedArray::getValue($value, $this->configuration['indexes'], $key_exists);
. What's that good for? Set indexes to['und', 0, 'value']
and it's quite visible.Comment #13
webchickMuch better. :)
Committed and pushed to 8.x. Thanks!