Simple permissions for uploads per node type
Simple bit of Drupal module code from yesterday: permissions are provided for each node type which can have attachments, providing a more granular permission set based on node type. Then, we alter any node add/edit forms and set the #access property for the attachments part of the form based on these new permissions.
Check the code out after the break, hope its of some use somewhere. Does anyone have any thoughts on Cheers to those who commented, I've modified the snippet accordingly.unsetting form elements like this? Is it a wise thing to do, or is there a better way?
/* @file attachments_by_nodetype.module * * Simple granular permissions for uploading files per node type. */ /* Implementation of hook_perm(). */ function attachments_by_nodetype_perm() { $permissions[] = "upload files to $type nodes"; } } return $permissions; } /* Implementation of hook_form_alter(). */ function attachments_by_nodetype_form_alter($form_id, &$form) { if ($form['type']['#value'] .'_node_form' == $form_id) { } }
articles
latest comments
Anonymous (not verified)
leafish_paul
leafish_paul
Anonymous (not verified)
leafish_paul
latest tweets
- Wise words heard at dental hospital: 'I hate dentists, they're so in your face.' — 1 week 2 days ago
- anyone recommend any decent find/hire a freelance designer type sites? — 2 weeks 3 days ago
- pleased with Ubuntu 8.10 on his crappy Dell 'top: http://tinyurl.com/5upsg5 — 3 weeks 3 days ago
- worried why the Ubuntu 8.10 beta installer insists on crashing at 29% — 4 weeks 1 day ago
- has one year of non-digital TV left. — 4 weeks 1 day ago

Mark Boulton Design: Drupal.org, Design Iterations, and Designing in the open
Plus de 20 endroits où trouver de superbes wallpapers | Cerium's blog
Open editing is here to stay
Pringles are not crisps
From The Mouths Of Highly-Paid TV Presenters...
















$element['#access'] = FALSE
$element['#access'] = FALSECheers Mr Anonymous
Ta for that! However, it looks to me from the Form API notes that this attribute was added in Drupal 6?
Unfortunately, the site the code is used on is based on Drupal 5.
In Drupal 5
It's available in Drupal 5 but for some reason isn't in the documentation.
Actually... it's just undocumented.
If you check out the node_form() function (at http://api.drupal.org/api/function/node_form/5 ) in d5 you'll find:
// Node options for administrators $form['options'] = array( '#type' => 'fieldset', '#access' => user_access('administer nodes'), '#title' => t('Publishing options'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 25, );However the FAPI documentation does not cover it. Patch time?!
Edit: yes indeedy! Paul
User 1 should always be allowed to do anything...
so
'#access' => FALSE
should maybe be something like
'#access' => user_access('user 1 only')
where 'user 1 only' could be any old string, since the function always returns true for U1...
Docupatcheration
Documentation patch for 5.x branch here.
Post new comment