Sometimes, there is the need to assign the same field of the input csv file to different drupal fields. Take for example the attached image. This works ok.
The problem is with the 'download template' functionality. This field appears twice, in the template. It should appear only once.

Comments

msti’s picture

Status: Active » Needs review
StatusFileSize
new845 bytes

This patch fixes the problem described above.

megachriz’s picture

It took me a few seconds before I understood what you meant with 'download template'.

Here are the steps to reproduce the error:

To reproduce the issue:

  1. Create an importer with a CSV parser.
  2. Add two mappers using the same source field, for example:
    email > Email address
    email > User name
  3. Go to /import and select the importer you created.
  4. Click on the link "Download a template" (import/myimporter/template).

Actual result:

email,email

Expected result:

email
megachriz’s picture

I can confirm the patch in #1 fixes the bug: after applying the patch, I get each column only once in the template.

The patch has some minor coding style issues though: after a comma should come a space:
+ elseif (!in_array(check_plain($mapping['source']),$sources) && !in_array(check_plain($mapping['source']),$uniques)){No space before $sources, $uniques and {

+ elseif (!in_array(check_plain($mapping['source']), $sources) && !in_array(check_plain($mapping['source']), $uniques)) {Spaces included

Also, I think it makes the code more readable if the check for existing columns is done once. The attached patch first does a check for existing columns before deciding whether the column should be added to $uniques or $sources.

msti’s picture

This patch fixes an related:

Just above the 'Download a template' link, there is a list of the fields that show in the csv file. This list also contains duplicates.
This patch removes the duplicates.

megachriz’s picture

twistor’s picture

Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.