0

I'm trying to import a CSV file into content type and paragraphs. But I can't get all the values stored in a cell. Here is my cell:

2022-07-13 2022-05-24,2022-06-06 2022-08-08 & 2022-07-16 2022-05-28,2022-06-08 2022-08-09

In this example, i have 2 modules:

  • The first before the '&'
  • The second after the '&'

But there may be more.

I created a custom content type with 2 dates called session.

Each module contains X sessions. each session is separated by ',' and each date of session is separated by ' '.

Here is one line of my csv file:

Code_LSO;Titre;Annee_de_creation;Cloture_des_inscriptions;Contenu;Famille_d_emploi;Intervenants;Introduction;Lieu;Nature_des_agents;Nombres_de_jours;Objectifs;Ouvertures_aux_ecoles;Places_disponible;Sous_Direction;Theme;Type;modules

545216;Aptent Decet Exputo Utrum;2022-02-17;2021-10-08;Accumsan amet aptent autem.;famile d’emploi 5;One guy;Abluo decet dolore.;Reims;bocrotoci;684;Ad amet et facilisis feugiat ludus tincidunt vereor.;Abbas immitto imputo usitas.;168;hufriehbfurezbfriezfrugyie;Services administratifs régionaux et interrégionaux;Formation;2022-07-13 2022-05-24,2022-06-06 2022-08-08 & 2022-07-16 2022-05-28,2022-06-08 2022-08-09

My migration file for the content_type:

uuid: 0178d6be-330f-4df6-aa52-46a0fbf50b82
langcode: en
status: true
dependencies: {  }
id: format
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - CSV
migration_group: format
label: 'format migration from CSV'
source:
  plugin: csv
  path: /var/www/generatedform.csv
  delimiter: ;
  header_row_count: 1
  ids:
    - Code_LSO
process:
  type:
    plugin: default_value
    default_value: formations_et_stage
  title: Titre
  nid: Code_LSO
  field_code_lso: Code_LSO
  field_annee_de_creation/value:
    plugin: format_date
    from_format: Y-m-d
    to_format: Y-m-d
    source: Annee_de_creation
  field_cloture_des_inscriptions/value:
    plugin: format_date
    from_format: Y-m-d
    to_format: Y-m-d
    source: Cloture_des_inscriptions
  field_contenu/format:
    plugin: default_value
    default_value: full_html
  field_contenu/value: Contenu
  field_famille_d_emploi: Famille_d_emploi
  field_intervenants: Intervenants
  field_introduction/format:
    plugin: default_value
    default_value: full_html
  field_introduction/value: Introduction
  field_lieu:
    -
      plugin: skip_on_empty
      method: process
      source: Lieu
    -
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle: lieu
      value_key: name
      bundle_key: vid
  field_nature_des_agents: Nature_des_agents
  field_nombres_de_jours: Nombres_de_jours
  field_objectifs/format:
    plugin: default_value
    default_value: full_html
  field_objectifs/value: Objectifs
  field_ouvertures_aux_ecoles: Ouvertures_aux_ecoles
  field_places_disponible: Places_disponible
  field_sous_direction: Sous_Direction
  field_theme:
    -
      plugin: skip_on_empty
      method: process
      source: Theme
    -
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle: theme
      value_key: name
      bundle_key: vid
  field_type:
    -
      plugin: skip_on_empty
      method: process
      source: Type
    -
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle: type
      value_key: name
      bundle_key: vid
  field_modules:
    plugin: migration_lookup
    migration: migration_paragraph_modules
    source: id
destination:
  plugin: 'entity:node'
migration_dependencies: {migration_paragraph_modules}

My migration file for the paragraph:

uuid: 93301879-890a-41f8-9024-b3285218b6a7
langcode: en
status: true
dependencies: {  }
id: migration_paragraph_modules
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - CSV
migration_group: format
label: 'format migration from CSV'
source:
  plugin: csv
  path: /var/www/eng/generatedform.csv
  delimiter: ;
  header_row_count: 1
  ids:
    - Code_LSO
process:
  field_modules:
    -
      plugin: skip_on_empty
      method: process
      source: modules
    -
      plugin: explode
      delimiter: ' & '
    -
      plugin: sub_process
      process:
        field_session:
          -
            plugin: skip_on_empty
            method: process
            source: modules
          -
            plugin: explode
            delimiter: ','
          -
            plugin: sub_process
            process:
              -
                plugin: explode
                delimiter: ' '
                source: modules
              -
                field_session/date_debut: null
                plugin: extract
                index:
                  - 0
              -
                field_session/date_fin: null
                plugin: extract
                index:
                  - 1
destination:
  plugin: 'entity_reference_revisions:paragraph'
migration_dependencies: null

Here is a screenshot of my paragraph: Paragraph

I relied on this and this research but it was impossible to get a result. If someone can help me. thanks!

4
  • This will not work: `migration_lookup´ uses one ID as source and returns one entity (paragraph or node).
    – Hudri
    Commented Jul 13, 2022 at 9:45
  • Using paragraphs (or any other entity reference revision ERR) as migration destination IMHO is generally a bad idea, because paragraphs/ERR revisioning is tied to its parent node, and therefore you can't reliably update existing paragraphs with migrations. Try to use entity_generate and create the paragraphs within the node migration.
    – Hudri
    Commented Jul 13, 2022 at 9:52
  • Thank you for your answer @Hudri So, i have to try to do all in one migration file ?
    – Buge
    Commented Jul 13, 2022 at 12:33
  • Maybe this helps: drupal.org/project/migrate_plus/issues/3238343
    – Hudri
    Commented Jul 13, 2022 at 12:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.