Closed (fixed)
Project:
Media Alias Display
Version:
1.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Jul 2022 at 10:07 UTC
Updated:
1 Sep 2022 at 14:44 UTC
Jump to comment: Most recent
Comments
Comment #2
codebymikey commentedSome cursory code reviews:
path_aliasmodule in the Controller, so should probably be declared in the module dependencies definition.$responseobject initially created here is no longer used.Comment #4
smustgrave commentedThank you for reporting and the feature request. This was one of my first modules so definitely room for improvements. To make sure this ticket doesn't include too much I opened
#3295337: Create config schema
#3295338: Update module dependency to include path_alias
Comment #5
smustgrave commentedSo addressed #3295338: Update module dependency to include path_alias already and #3295337: Create config schema I'm reviewing
To implement something like media_entity_download think we would need to extend the image formatter most likely with one of these hooks https://www.drupal.org/node/2130757
That along the lines you were thinking?
Comment #7
codebymikey commentedThanks for the relatively quick fix!
Haha, I wasn't even thinking that far ahead, I was just thinking of having a query string like
?attachmentor?dldetected in the controller which determines whether the media item should be forcefully downloaded as an attachment when necessary even if the browser can typically open it inline just fine (aka., the current default behaviour, which I'm fine with).The media entity may contain documents and archives file rather than images, so the image formatter approach might not be a feasible solution (unless I'm misunderstanding the scope of the implementation).
media_entity_downloadimplements its own formatter to address a similar issue to this, I don't personally need a one size fits all disposition for all media entities, I think it makes sense for it to be on an entity by entity basis, by specifying the query string where necessary (and is more of a power user tool).Comment #8
smustgrave commentedI'm just glad this module is proving useful for others!
I think we can add the detection of ?attachement under this ticket. And open a new one for making it configurable. You're right will need to have a hook that's dynamic based on the field (image or file).
So for this one
Missing anything?
Comment #9
codebymikey commentedNope, that all makes sense to me :)
Comment #10
smustgrave commentedReady for review
Comment #11
codebymikey commentedI didn't wanna update the PR without first getting feedback from you, so I've added some of my thoughts on the PR to get your input on them.
Comment #12
smustgrave commentedall fantastic feedback. And go for it! no issues here
Comment #13
smustgrave commentedMade some updates based on the feedback but the tests are still failing.
Comment #14
codebymikey commentedI also made some changes and had the tests failing locally, so didn't wanna push them up until I had time to debug why.
Most of the changes were pretty innocent, so was slightly interesting to see the tests fail.
I fixed the initial failed test (I think this is the one you're also having) which were because all calls to
$this->createMedia();essentially share the same underlying file entity internally, so after unlinking it here, subsequent calls to it will have the file missing from disk and lead to inconsistent behaviour, the files need to be unique per$this->createMedia();call.I then ran into another issue with the failed test when I introduced custom path aliases to ensure the behaviour was still consistent with or without aliases, this is what I have in my backlog to fix before I push up.
Comment #15
codebymikey commentedAnd lol, slightly interesting to see @immaculatexavier supposedly made their first commit to this issue’s fork and was given a draft credit, but there's no actual commits. Wonder what happened there.
Comment #16
smustgrave commentedI’ll fix the credit before marking complete. And wonder if it’s a routing issue? When I append ?download it works but redirects back to media/123 so maybe that’s why content header isn’t updating?
Comment #17
smustgrave commentedSo for now I don't mind commenting out those test cases. Can't figure out why it's not registering the content header. Looked at the examples you provided and doing almost hte same as them.
Anyway besides those is there anything else failing?
Comment #19
codebymikey commentedFixed the broken test cases, it was related to the test case reusing the same test file internally (especailly during deletions), as well as
$this->file, which meant the test was referencing the wrong file instance while doing its comparisons. I've moved the references into local variables with appropriate names, as well as removed reliance on thepath_aliasmodule.It shouldn't be necessary for this to work since the controller shouldn't be concerned with the alias at that point. It should've already resolved the media entity it's working with.
The change introduces a bunch of other minor improvements, so I've added them in a new branch for review/cherry-picking purposes.
Comment #20
smustgrave commentedNice! Merged