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.
Currently, to programmatically create or revoke grants on nodeaccess, we need to build $form and $form_state elements. Would be better to expose these operations as an API.
Comments
Comment #1
vlad.pavlovic CreditAttribution: vlad.pavlovic commentedI couldn't agree more, this is definitely on my TODO list.
Comment #2
bogdog400 CreditAttribution: bogdog400 commentedYes, BUMP. Something that would make this all a bit less dangerous and complex. Building a $form is a waste just to take it apart.
Comment #3
samwilson CreditAttribution: samwilson commented+1
Comment #4
bogdog400 CreditAttribution: bogdog400 commentedI've been experimenting with this by just inserting the right line into the database table, nodeaccess. Is this dangerous? Are there some caching issues?
Comment #5
samwilson CreditAttribution: samwilson commentedYes, I guess that works for individual-node permissions? (Does it?) I've been playing with similar things for the default content type and role-permissions by setting the
nodeaccess_TYPENAME
variable. So to e.g. give authenticated users read access to 'page' type nodes, the following:But really it all feels too hacky... :)
Comment #7
vlad.pavlovic CreditAttribution: vlad.pavlovic commentedAdded two new hooks: hook_nodeaccess_grants_alter and hook_nodeaccess_grant_alter
These will allow modification to all grants and individual grants, respectively.
Comment #8
vlad.pavlovic CreditAttribution: vlad.pavlovic commentedComment #10
bogdog400 CreditAttribution: bogdog400 commentedThanks very much. I haven't tried it yet, but I'm grateful you put in the time.