API page: https://api.drupal.org/api/drupal/modules%21system%21system.module/funct...
The current documentation states that the return value will be "On success the location the file was saved to, FALSE on failure." If the "managed" argument was used, the return value will actually be a file object, and not a location string. The location string is only returned for an unmanaged file.
Comments
Comment #1
Anonymous (not verified) commentedUpdated title to be more reflective of issue
Comment #2
jhodgdonThanks for filing this issue! I agree completely with your analysis.
We need to fix this in drupal 8.x first, and then backport to 7. In 8, the return value for a managed file is a \Drupal\file\FileInterface file entity (see file_save_data() function).
Comment #3
Anonymous (not verified) commentedAlso as a further update to this - the documentation should probably reflect that the function will also generate a variety of Drupal messages if the function was unable to successfully obtain the file, and not just return FALSE.
This function should probably be modified to return the error to the calling function, allowing that function to determine what happens on an error. Right now this function makes the assumption that a message should be generated and displayed, and provides no way to suppress or modify those messages. A separate issue has been created for this here - https://drupal.org/node/2177545
Comment #4
jhodgdonThanks! This issue can stay about just the documentation then.
Comment #5
anemes commentedI can work on this.
Comment #6
anemes commentedComment #7
jhodgdonI think this return value documentation would be clearer if it was formatted as a list? Something like:
Comment #8
anemes commentedI also changed the variable comments for this function from "@param $name type" to "@param type $name". I hope there is no problem with this.
Comment #9
anemes commentedComment #10
jhodgdonThanks! Definitely those changes are welcome, and it is common in documentation patches to fix other errors in the same function documentation that is being fixed up.
However, you should use "bool" and not "boolean" for param/return types. There's documentation on this at:
https://drupal.org/coding-standards/docs#types
For extra credit, you could also remove the blank lines between the @param documentation (there should be a blank line between the end of the @param section and @return however).
Do you think it would also make sense on this line:
to have some description of what this means, like "a \Drupal\file\FileInterface object with information about the saved file"? or something like that?
Comment #11
anemes commentedComment #15
anemes commentedAdded new patch because previous one failed.
Comment #17
skipyT commented15: Incomplete-return-values-documented-for-system_retrieve_file-2174353-15.patch queued for re-testing.
Comment #18
jhodgdonGreat, thanks!
Comment #19
jhodgdonThere is an "avoid commit conflicts" issue that also touches the system.module file: #1996238: Replace hook_library_info() by *.libraries.yml file
I'm being extra careful about these "avoid commit conflicts" issues, so I'm going to postpone committing this until that one is taken care of.
Comment #20
jhodgdonThanks all! I was able to commit this to both 8.x and 7.x, since I got leave from the authors of that other issue to commit it.