langcode: fr
status: true
dependencies:
  - migrate_google_sheets
  - migrate_plus
id: projet_node
label: 'Import des projets depuis Google Sheets'
migration_group: le_shed
source:
  plugin: projet_node
  data_fetcher_plugin: http
  data_parser_plugin: google_sheets
  constants:
    # Trailing slash: file_import keeps the original filename and copies the
    # image into this directory.
    images_destination: 'public://projets/'
  # The feed file for the spreadsheet. The Google Spreadsheet should be either “Public” or set to “Anyone with link can
  # view” in order for the feed to work.
  # Template: 'https://sheets.googleapis.com/v4/spreadsheets/<SHEET>/values/<TAB>?key=<KEY>'
  # La clé API n'est volontairement pas dans l'URL : le data_parser
  # google_sheets ajoute automatiquement la clé stockée en base
  # (config migrate_google_sheets.settings, réglée via l'UI du module).
  urls: 'https://sheets.googleapis.com/v4/spreadsheets/1561Gv1C-IlCTmg64Z8HnznvOeLbvwhA_k1l6aq95zFA/values/Projets'
  # Under 'fields', we list the data items to be imported. The first level keys
  # are the source field names we want to populate (the names to be used as
  # sources in the process configuration below). For each field we're importing,
  # we provide a label (optional - this is for display in migration tools) and
  # an selector (xpath) for retrieving that value. It's important to note that this xpath
  # is relative to the elements retrieved by item_selector.
  # For Google Spreadsheet XML feeds the actual columns are named with gsx: followed by the cleaned column name (lower,
  # limited punctuation, etc).destination:
  fields:
    -
      name: id
      label: 'Unique identifier'
      selector: 'UID'
    -
      name: title
      label: 'Title'
      selector: 'Nom du projet'
    -
      name: date_start
      label: 'Date start'
      selector: 'Date de début de projet'
    -
      name: date_end
      label: 'Date end'
      selector: 'Date de fin de projet'
    -
      name: projet_type
      label: 'Type de projet'
      selector: 'Type de projet'
    -
      name: curator
      label: 'Commissaria'
      selector: 'invité/accompagné/curaté par'
    -
      name: artistes
      label: 'Artistes invité·es'
      selector: 'Artistes invité·es'
    -
      name: partners
      label: 'Partenaires associés'
      selector: 'Partenaires associés'
  # Under 'ids', we identify source fields populated above which will uniquely
  # identify each imported item. The 'type' makes sure the migration map table
  # uses the proper schema type for stored the IDs.
  ids:
    id:
      type: integer
process:
  type:
    plugin: default_value
    default_value: projet
  title:
    plugin: skip_on_empty
    method: row
    source: title
    message: 'Projet ignoré : « Nom du projet » vide.'
  body/value: body_html
  body/format:
    plugin: default_value
    default_value: wysiwyg
  field_images:
    plugin: sub_process
    source: images
    process:
      target_id:
        plugin: image_resize_import
        source: uri
        destination: destination
        max_width: 1920
        max_height: 1920
        reuse: true
        skip_on_missing_source: true
      alt: alt
      image_field_caption/value: caption
      image_field_caption/format:
        plugin: default_value
        default_value: wysiwyg
  field_fichiers:
    plugin: sub_process
    source: pdfs
    process:
      target_id:
        plugin: file_import
        source: uri
        destination: destination
        reuse: true
        skip_on_missing_source: true
      description: description
  field_dates/value:
    plugin: leshed_date
    source: date_start
  field_dates/end_value:
    plugin: leshed_date
    source: date_end
    end_of_year: true
    fallback_source: date_start
  field_type_de_projet:
    -
      plugin: skip_on_empty
      method: process
      source: projet_type
    -
      plugin: explode
      delimiter: ','
    -
      plugin: callback
      callable: trim
    -
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle_key: vid
      bundle: type_de_projet
      value_key: name
  field_invite_accompagne_curate_p:
    -
      plugin: skip_on_empty
      method: process
      source: curator
    -
      plugin: personne_generate
      type_de_personne: curateur
  field_artiste_s_invite_s:
    -
      plugin: skip_on_empty
      method: process
      source: artistes
    -
      plugin: personne_generate
      type_de_personne: artiste
  field_partenaire_s:
    -
      plugin: skip_on_empty
      method: process
      source: partners
    -
      plugin: partenaire_generate
  uid:
    plugin: default_value
    default_value: 3
migration_dependencies: { }

destination:
  plugin: entity:node
