Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The fileEntityLoad function's code for creating files is: $file = file_save_data($output, 'public://' . $filename, FILE_EXISTS_RENAME);
This hardcoded path causes the files to be created in the root of the files directory regardless of config in the file field which places files into a subdirectory.
Comment | File | Size | Author |
---|---|---|---|
#11 | upload_to_destination_set_in_field_configuration-2938698-11.patch | 4.02 KB | cameron prince |
|
Comments
Comment #2
cameron prince CreditAttribution: cameron prince commentedComment #3
cameron prince CreditAttribution: cameron prince commentedFixes missing $entity_type argument.
Comment #4
cameron prince CreditAttribution: cameron prince commentedComment #5
sluceroEverything here looks good and seems to be working well. I'll mark this as needs review and hopefully we can get somebody else to confirm as well before committing.
Thanks @cameronbprince!
Comment #6
kedramonHi guys,
just tested it, works good!
Only one notice this function throwParamError don't return anything.
Comment #7
cameron prince CreditAttribution: cameron prince commentedAs a test, I removed the images directory and ran the import. throwParamError() printed out the params in the error as expected.
@kedramon, I assume you are expecting a "return" in the throwParamError() function itself. This is not needed because that function, in turn, calls throw itself.
More info: https://stackoverflow.com/questions/11547656/why-do-some-people-return-a...
Comment #8
cameron prince CreditAttribution: cameron prince commentedHere is a re-roll and new code to check for the existence of a file entity with the same URI as the file being imported. This will prevent the files directory from filling with duplicates when your imported content references the same image multiple times.
Comment #9
jasonawantA few questions about the check for existing files. For example, say we are using an image file that changes, but uses the same filename, what happens when checking the for the $file_uri? When we use the existing file, when actually want to use an updated image in the file?
If the desire is not create a duplicate, assuming the yaml_content is being processed again in effort to update the already created content, could we not use FILE_EXISTS_REPLACE with file_save_data()?
So, change
with
Comment #10
cameron prince CreditAttribution: cameron prince commented@jasonawant, I originally believed that would result in a duplicate file object pointing to the same file. But now, after reviewing the file_save_data code, I see that existing files are loaded when that option is set, so that should be fine. I'll update the patch.
Thanks!
Comment #11
cameron prince CreditAttribution: cameron prince commentedAnother re-roll with FILE_EXISTS_REPLACE.
Comment #13
sluceroI've just committed this and it will be included in the next alpha release (8.x-1.x-alpha4).
Thanks for all the work everybody!
Comment #14
sluceroAdding to the release plan ticket to record which release it will be included in.