When migrating data into drupal into a field with a text format, if you specify it like this:
'field_recipe_nutritional_info': basic_nutrition
and follow up the text format like this:
'field_recipe_nutritional_info/format':
plugin: default_value
default_value: 'full_html'
The field_recipe_nutritional_info data will always be blank and the format will not be set correctly.
If instead you specify this (note /value) it works fine. Both the value and the format are set correctly.
'field_recipe_nutritional_info/value':
'field_recipe_nutritional_info/format':
plugin: default_value
default_value: 'full_html'
In processRow() it calls $row->setDestinationProperty($destination, $value);
which overwrites the field value. whoops!
For reference, here is the rest of the project including the yaml file in question
| Comment | File | Size | Author |
|---|
Comments
Comment #2
selwynpolit commentedComment #3
mikeryanYes, it would seem that the unqualified form causes the entire field array to be written by that mapping. One might hope that it would somehow "know" what the primary value is and only write that specific value, but the Row class where this is happening knows nothing of field structures. We may need to simply document that when migrating multiple subvalues of a field, the primary value's subfield must be explicitly mapped.
Comment #4
quietone commentedI'm all for improving the documentation and this looks straightforward. Though, I'd prefer to have agreement before I change it. (Don't want to get it wrong and confuse folks.)
So, I reckon the information can go on Migrate process right after "Handling multiple values".
-- start example documentation --
Handling multiple subvalues of a field
The primary value of a field and all the subfields must be explicitly mapped. The following example uses the default_value plugin to map the format subfield.
-- end example documentation --
Comment #5
quietone commentedComment #7
mikeryanComment #9
prash_98 commentedHave added the comment for the same. Please review it.
Comment #10
prash_98 commentedSorry attached the same patch file twice by mistake.
Comment #11
jofitzFirstly thanks for your contribution, @prash_98 - welcome to Drupal!
I'm afraid I doubt this is where @mikeryan and @quietone intended for the documentation to appear. Out of interest, why did you choose this file?
But before I'd even noticed that, I had a few points of feedback:
+ * Along with thw the text also specify the text value.+ * Along with the the text also specify the text value..Comment #12
Munavijayalakshmi commentedComment #13
prash_98 commentedThanks and would surely keep this in mind for the issues ahead.
Comment #14
chiranjeeb2410 commented@prash_98
Make the changes accordingly in the correct file and then upload the patch.
Comment #15
Munavijayalakshmi commentedComment #16
jofitzComment #17
jofitzHelps if I add the files too!
Comment #18
heddnAssigning to myself for review.
Comment #19
heddnThe place for this documentation seems strange, as noted in #11. Let's move this either into the yml file for formats.
Comment #21
jofitzAdded the documentation suggested by @quietone in #4:
https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins/mi...
Comment #22
heddnSo, does #21 fix this? Or do we need to add a patch to change some doc block?
Comment #23
quietone commentedI've gone back and forth on this for the last wee while. Finally decided that it is a bit of a gotcha so it is better to add some documentation to processRow() about the consequences of
$row->setDestinationProperty($destination, $value);Comment #25
heddnWhile can figure out the "main" propery value (see FieldItemInterface::mainPropertyName), that main property isn't used for base fields. It seems too much work to figure out the difference. This seems like a docs only fix. Probably could live on the d.o. documentation page about working with process plugins and how nested values function.
Tagging.
Comment #26
masipila commentedBased on #25, this is handbook documentation fix only.
I checked our handbook and it covers this info, see https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins/mi...
Closing this as outdated. If someone feels that something else should be done under this issue, please re-open and specify the proposed actionable next steps.
Cheers,
Markus
Comment #27
diamondseaFor cases (such as XML files) where there may be zero, one or multiple value fields to be imported from the selector, the documented solutions don't work.
#3586125: Add text_format process plugin for setting text format on multi-value fields supports any number of input fields, preserving the input format for each of them.