Score:0

How to set media field mappings to autofill the target fields when uploading the file instead of saving to those files when saving the media entity

cn flag

I am using the document media type for pdfs. I am also utilizing the field mappings for:

  • Name
  • MIME Type
  • File size
  • and I will be adding a field mapping for the pdfs subject as well using a Media source plugin.

These are working as expected when I save the media entity; however, I have the additional requirement that the Name and Subject fields will be auto-populated when a file is initially selected. The user creating the media entity will then be able to see the name and subject in their respective fields and can change these if desired.

I have tried adding the ajax call for the file field in a form alter; however, I don't believe that this will work because the managed_file type already uses ajax.

I have also tried to create a custom Element using the idea from another question but that doesn't seem to be working either. The field is in a widget, and so when I update the field type like this: $form['field_media_document']['widget'][0]['#type'] = 'my_managed_file';, it seems my callback is never triggered.

Thank you in advance for any ideas or insights on how to get the pdf metadata to prepopulate the media fields after selecting the file.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.