1

I have a constant defined in my migration definition like so:

  constants:
    destination: "private://working_papers/"

There are 30,000 files that will come in as part of the migration. I would like to create directory destinations on the fly, based on source field values or whatever I want.

So:

destination: constants/destination

Would become:

destination: constants/destination/@source_field_value/@source_field_value2

This would be to reduce the raw number of files appearing in a given directory. When I try the above, nothing happens, even though the migration succeeds. The files don't go anywhere.

How can I do this? For reference, here is the field in the process section of the definition:

  field_paper_working_paper:
    plugin: file_import
    source: doc_format_url
    destination: constants/destination
    uid: 1
    rename: TRUE
2

You can chain a concat process plugin to your destination property so that it contains the result of concatenated source & constant values:

field_paper_working_paper: 
  plugin: file_import 
  source: doc_format_url 
  destination: 
    plugin: concat
    source:
      - constants/destination
      - '/'
      - source_field_value
      - '/'
      - source_field_value
  uid: 1
  rename: TRUE
  • I thought it would be this easy, and I tried this, but I get this error in the console: "[error] TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given" when I set it back, the error goes away. – Kevin Mar 7 at 18:29
  • Ah, I think it might either be related to the plugin not excepting string constants or @field values. I've seen this problem unfortunately it was about 6-9 months ago so my memory is fuzzy. – Shawn Conn Mar 7 at 18:34
  • Wait, I am checking the FileImport plugin. I may have done it wrong. – Kevin Mar 7 at 18:35
  • I have the pseudo field setup in the migration, but its not adding the source field value on the end. – Kevin Mar 7 at 18:42
  • 2
    I think they reference other destination fields defined in the migration itself. For example if you had a field_foo field defined in the YML, at the same level as field_paper_working_paper, you can get access to the result of that migrated value with @field_foo. Source columns/cells/whatever you want to call them don't need the same special syntax as they're already covered just using the name – Clive Mar 7 at 21:36

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.