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

Anonymous’s picture

Title: Incomplete return values documented » Incomplete return values documented for system_retrieve_file

Updated title to be more reflective of issue

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7, +Novice

Thanks 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).

Anonymous’s picture

Also 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

jhodgdon’s picture

Thanks! This issue can stay about just the documentation then.

anemes’s picture

I can work on this.

anemes’s picture

Status: Active » Needs review
StatusFileSize
new703 bytes
jhodgdon’s picture

Status: Needs review » Needs work

I think this return value documentation would be clearer if it was formatted as a list? Something like:

One of these possibilities:
- If it succeeds and $managed is FALSE, ...
- If it succeeds and $managed is TRUE, ...
- If it fails, FALSE.
anemes’s picture

I also changed the variable comments for this function from "@param $name type" to "@param type $name". I hope there is no problem with this.

anemes’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Needs work

Thanks! 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:

+ *   - If it succeeds and $managed is TRUE, \Drupal\file\FileInterface.

to have some description of what this means, like "a \Drupal\file\FileInterface object with information about the saved file"? or something like that?

anemes’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB

Status: Needs review » Needs work

anemes’s picture

Status: Needs work » Needs review
StatusFileSize
new1.82 KB

Added new patch because previous one failed.

Status: Needs review » Needs work
skipyT’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Great, thanks!

jhodgdon’s picture

There 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.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.