Allowing Users to modify node authoring information
I recently completed a Drupal 5 project that required certain users to have the ability to edit part of the node attribute information. The two node attribute fields are author and created. Under normal circumstances a user may only edit this information if they are assigned the "administer nodes" permissions. This was not an option on this project.
I spent quite a bit of time looking in Drupal.org for a module that would override the author permissions in Node to no avail. There were some useful posts in the forum (http://drupal.org/node/282494) that lead me to a solution. Based on what I could find the only viable option was to custom code a module. Fortunately it was a nice easy module.
The key to granting users access to node attributes is the "[#access]" attribute in FAPI. I needed to create a module that would create 2 permission sets (1 for each author attribute) then use the hook_form_alter to modify default permissions. The code is below:
/** * Implementation of hook_perm() **/ function modify_authoring_information_perm() { return array('modify created date', 'modify author'); } /** * Implementation of hook_form_alter() * This will target ALL node edit forms **/ function modify_authoring_information_form_alter($form_id, &$form) { //global $user; if(strpos($form_id,'_node_form')) { $form['author']['#access'] = user_access('modify created date') || user_access('modify author') || user_access('administer nodes'); $form['author']['name']['#access'] = user_access('modify author') || user_access('administer nodes'); $form['author']['date']['#access'] = user_access('modify created date') || user_access('administer nodes'); } }
The first function just creates a list of permissions to display in the user administration page. The second function is where the magic happens. It checks to see if the form_id is a node edit form by looking for the '_node_form' string. If the current form is a node edit form it alters the permissions.
- Login to post comments