Many contrib modules (and core itself) use file_stream_wrapper_uri_normalize() to ensure that a URI is correct. As is, there is no way for a contrib module adding a stream wrapper to add it's own validation or conditions when normalizing a URL. For example, with the S3 SDK, all URIs must be within a bucket, and a URI like s3://image.jpg is invalid. With this alter hook, a module can alter a URI as needed to meet it's own conditions.
A cleaner option might be to add a normalize method to the stream wrapper interface, and call that directly, but an alter hook seems like the least invasive option while preserving API compatibility.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 2479523-nr-bot.txt | 153 bytes | needs-review-queue-bot |
| #18 | 2479523.17-normalize-alter-hook.patch | 1.63 KB | deviantintegral |
Comments
Comment #1
deviantintegral commentedComment #2
bleen commentedHere testbot ... here boy
Comment #3
larowlanWe need a test for the new functionality, but other than that - looks good to me.
Comment #4
travelerttApplied this patch to site running Drupal 7.37 and my Upload field disappeared.
Using Media and patches from the AmazonS3 project page:
https://www.drupal.org/node/2479483#comment-9872933
https://www.drupal.org/node/2482757#comment-9889991
https://www.drupal.org/files/issues/2479473.5-upload-params.patch
Comment #5
amaisano commentedThis patch had no effect for me - Drupal still cannot delete s3:// files, even when the entities they are attached to have been deleted. With or without this patch I had no issues uploading/adding s3:// files.
This is the error I am getting (upon trying to delete):
User warning: A URI must be set before calling getOptions(). in Aws\S3\StreamWrapper->triggerError() (line 785 of /Users/Adamo/GIT/nexamp/public_html/sites/all/libraries/composer/aws/aws-sdk-php/src/Aws/S3/StreamWrapper.php).
Comment #6
cilefen commented@amaisano Did you implement hook_file_stream_wrapper_uri_normalize_alter() with this patch applied?
Comment #7
amaisano commentedAll I did was apply the patch - no other steps...
I did however just switch to the latest dev version of amazons3 7.x-2.x-dev and now files are getting deleted as expected when the entity they are attached to is deleted. I'm no longer getting these errors on the latest dev, so something from one of the last 8 commits fixed it for me.
Comment #8
cilefen commented@amaisano For this particular patch to work, you have to make a module with an implementation of hook_file_stream_wrapper_uri_normalize_alter(). That is why I asked.
Comment #9
amaisano commentedAh, I see. However, I checked both the stable and dev releases of amazon s3 and both did have such a hook:
Comment #10
cilefen commentedI am confused—there is no such hook in core. This issue would add one.
It would be good to offer some example code here.
Comment #11
amaisano commentedTo clarify, I reverted my core files to vanilla (both files addressed in this patch) and AmazonS3 continues to work fine, even though the amazons3.module has this hook. Neither the 1.1 or 2.x versions of the AmazonS3 module are giving me problems, but perhaps I'm just not noticing them.
Comment #12
bleen commentedSo, if you are testing with a valid URI (ex. s3://my-bucket/image.jpg) then you will not see any problems at all, but without the patch in #1 there is nothing to
validateenforce that your URI is acceptable to S3. Make sense?Comment #13
deviantintegral commentedI'm pretty sure the issues all reported above are related to contrib modules or patches to contrib, and not this specific alter hook, so I'm bumping this back to needs review.
Comment #14
jwilson3Comment #10 is asking for some example code inside the api hook definition. Sounds like a good idea to me. I couldnt find one hook in system.api.php that didnt have at least one line of example code.
Also the docblock for the new hook is very light, compared to all of the other examples in system.api.php
Finally, shouldn't this be added to Drupal 8 then backported first?
Comment #15
cilefen commentedYes, all feature requests should be in 8.1.x now.
Comment #16
deviantintegral commentedGood call - I'd thought this function was removed entirely in D8. Here's a reroll with simplified docs based on the hook implementation in the amazons3 module.
Comment #18
deviantintegral commentedFixes trying to call alter() in tests when the moduler_handler service isn't available.
Comment #19
deviantintegral commentedComment #26
pedrospStill applying .1 patch to core 7.64, but honestly not sure if still needed :)
I update this issue to ping other folks in this thread.
Comment #27
andypostComment #28
berdirI'm not sure if a hook is the right approach here, maybe this should instead be a method on the stream wrapper that could be implemented?
Comment #36
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.