In my Drupal 8.4 installation I use the module File Entity. In the module are defined a few additional fields: 'author', 'title', 'alt',... My migration works. The files are imported, but the additional fields are after the import empty.

The complete YML (modules\my_migration_module\config\install\migrate_plus.migration.files.yml) looks like:

langcode: en
status: true
id: files
migration_group: import_xml
label: 'Import the test XML file'
  plugin: url
  data_fetcher_plugin: file
  urls: 'http://example.org/test.xml'
  data_parser_plugin: xml
  item_selector: /imports/files
      name: id
      label: ID
      selector: ./@id
      name: title
      label: Title
      selector: ./@title
      name: alt
      label: Alt
      selector: ./@alt
      name: author
      label: Author
      selector: ./@author
      name: filename
      label: Filename
      selector: ./@filename
      name: uri
      label: URI
      selector: ./@uri
      name: target
      label: Target
      selector: ./@target
    - id
      type: string
  field_alt: alt
  field_title: title
  field_author: author
  filename: filename
    plugin: download
      - uri
      - target
  plugin: 'entity:file'
  source_path_property: uri
  destination_path_property: target
template: null

E.g. for the field title I have tried:

field_title: title
title: title
field_title/field_title_value: title
field_title/field_title_value: title
field_title/field_title: title
file__field_titel/field_title_value: title
file__field_titel/field_title: title

I have found a solution for a similar problem in Drupal 7: How to migrate fields attached to files? I'm not sure, how can I implement this in Drupal 8.

  • Do you migrate files with additional fields from d7 to d8? Have you tried to implement a custom source plugin? There you can specify on prepareRow() function some additional fields to migrate. – OPTASY Nov 13 '17 at 19:56
  • No, I import the files from XML. – Antonín Slejška Apr 13 '18 at 12:21
  • Have you tried using simple_xml instead of xml as data_parser_plugin? I also had a some problems with a XML import that were solved by changing nothing execpt the data_parser_plugin – Hudri Apr 13 '18 at 12:31
  • I have tried to change 'data_parser_plugin: xml' to 'data_parser_plugin: simple_xml'. But it did not helped. And I've got then the warning "Illegal string offset 'x-default' ContentEntityBase.php:949", – Antonín Slejška Apr 13 '18 at 13:07
  • I have found the following issue. May be it is the reason, why the additional fields are not imported. See: drupal.org/project/drupal/issues/2822545 – Antonín Slejška Apr 13 '18 at 13:18

The YML code is correct. But there is an issue in Drupal core: https://www.drupal.org/project/drupal/issues/2822545

There is also a patch. I have tested the patch and it works: https://www.drupal.org/files/issues/2822545-cannot_update_file_properties-6.patch

The patch can be installed with Composer:

    "require": {
        "cweagans/composer-patches": "~1.0",
        "drupal/core": "8.4.6",
    "extra": {
        "patches": {
           "drupal/core": {
             "Solve the issue when migrating files with additional fields": "https://www.drupal.org/files/issues/2822545-cannot_update_file_properties-6.patch"

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.