0

I have a csv places column with values like that:

Madrid|Spain
Barcelona|Spain

I want to migrate this places to a custom taxonomy and 3 terms (Madrid, Spain, Barcelona) get generated doing it like that:

  field_taxonomy_places:
    -
      plugin: explode
      source: places
      delimiter: '|'
    -
      plugin: entity_generate

But actually I only want to create cities (Madrid, Barcelona), but not countries. So I try to take the first value till the delimiter like that:

field_taxonomy_places:
    -
      plugin: explode
      source: places
      limit: 1
      delimiter: '|'
    -
      plugin: entity_generate

The problem is that now 2 terms get generated (Madrid|Spain, Barcelona|Spain).

1

Just found the solution after rereading the PHP explode docs:

If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

So setting the limit to 1 has the effect that the returned array element contains the rest of the string, which in my case is the whole string. So setting the limit to 2 fixes the problem and gives back the first part of the string:

field_taxonomy_places:
    -
      plugin: explode
      source: places
      limit: 2
      delimiter: '|'
    -
      plugin: entity_generate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.