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.
I think the media_set_browser_params() function have two error:
1. If $params is an empty array the media_set_browser_params() function don't call hook_media_browser_params_alter() hook, because PHP cast empty array to FALSE like NULL. I suggest use "===" instead of "!".
2. hook_media_browser_params_alter hook call whith $stored_params, not $params. (why use & there?)
please see the patch.
The patch works 7.x-2.x-dev and 7.x-1.x also.
Comment | File | Size | Author |
---|---|---|---|
#10 | 1238118-media-browser-set-params.patch | 1.42 KB | Dave Reid |
#8 | media_browser_params_alter-1238118-8.patch | 473 bytes | idflood |
#3 | media_browser_params_alter-1238118-2.patch | 499 bytes | pp |
#1 | media_browser_params_alter-1238118-1.patch | 498 bytes | aaron |
media_browser_params_alter.patch | 499 bytes | pp | |
Comments
Comment #1
aaron CreditAttribution: aaron commentedthis all looks right. except i think you should use !isset() rather than == NULL... the attached patch does that.
Comment #2
aaron CreditAttribution: aaron commentedrtbc, assuming it passes the test...
Comment #3
pp CreditAttribution: pp commentedok, but i think we should use is_null() rather than !isset(). The $params variable always exists. We shouldn't test the $params variable exist or not (isset), We sould test the $params variable is null or not. (is_null, isset)
Comment #4
Dave Reid!isset() is always preferred over is_null()
Comment #5
pp CreditAttribution: pp commentedWhy? Is it a Drupal wodo?
Comment #6
pp CreditAttribution: pp commentedIsset is faster.
Comment #7
aaron CreditAttribution: aaron commentedyes, !isset() is faster, and doesn't throw an error if passed a variable that hasn't yet been set. the only place where is_null() might be preferred is if passing in a function call, which is bad practice anyway.
Comment #8
idflood CreditAttribution: idflood commentedI have no doubt in the first point exposed in #1. But the second about $stored_params seems a bit wrong to me. At least, the solution provided in #1245430: media_set_browser_params should use reference of $params looks more coherent.
Here is a patch with a mix of both solution. I don't know how to test this manually though.
Comment #9
idflood CreditAttribution: idflood commentedComment #10
Dave ReidI think this is actually the more proper solution:
Comment #11
pp CreditAttribution: pp commented#10 It is the best solution.
Comment #12
Dave ReidCommitted #10 to both 7.x-2.x and 7.x-1.x.
http://drupalcode.org/project/media.git/commit/fda6f10
http://drupalcode.org/project/media.git/commit/1cda239