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.
URL parameters like gids_node=id are not taken into account if the user lacks access to the field. This is odd if you just want to hide the field from the user but provide some links that put content in the right group.
Attached patch fixes that by implementing a default-value function that takes the og-context from URL into account - as the UI. Using this function ensures that the field API stores the correct value regardless whether the form widget is actually shown.
Comment | File | Size | Author |
---|---|---|---|
#8 | og_field_defaults.patch | 1.84 KB | fago |
#7 | og_field_defaults.patch | 1.8 KB | fago |
#3 | og_field_defaults.patch | 1.78 KB | fago |
og_field_defaults.patch | 1.77 KB | fago | |
Comments
Comment #1
amitaibuCool, didn't known about this callback. The function should check for the user's access to the groups in the URL, to prevent from submitting it to inaccessible groups. Also, we also need to take care of existing groups. (the widget currently has element validate callback that re-adds those groups)
Comment #2
amitaibuMaybe we can move the whole logic from og_field_widget_form() dealing with the default value over to that function.
Comment #3
fagoI've re-rolled the patch and added the access check to groups in the URL.
>Also, we also need to take care of existing groups. (the widget currently has element validate callback that re-adds those groups)
The function is only taken into account if the entity is created. Else the field API takes the values out of $entity, so the function is not called. Consequently, we cannot move the whole value handling over to it.
Comment #4
amitaibuPatch looks good.
Maybe better to use og_load_multiple()
A small test would be much appreciated :) (If you don't have time, I'll do it).
Comment #5
fago>Maybe better to use og_load_multiple()
Oops. Done so.
>A small test would be much appreciated :) (If you don't have time, I'll do it).
Makes sense, though tests require setting up field access first. Do you have already tests for that? I guess I'll better leave it up to the og master.. ;)
Comment #6
amitaibuPatch? :)
Comment #7
fagoops again. :/
Comment #8
fagoRe-rolled to apply against latest dev version.
Comment #9
amitaibuAdded tests and committed, thanks!
Comment #10
fagoGreat, thanks!!
Comment #11
amitaibu@fago, btw, checkout -- #1263118: Have equivalent of Node Reference URL Widget