0

In the node type page I've added one Integer field "field_article_rejected". When in rejected stated it contains 1.

But when a registered user changes and "Saves" it I want to set the value of it to 0.

Also the registered user does not have read/write permission on this field. But if needed I can give the user permission for this field but I'll hide it in "Display fields"

How to do it?

I'm working on Drupal-6.

To explain what I'm doing: I've created an article directory. So an user will log-in and create an article type of page. So now this page will be shown as "Submitted articles" block using views.

But as an admin when I reject it then I want this article to be shown under "Rejected Articles" block to the user. So I want to use field "field_article_rejected". When 0 it means user has sumbitted and when 1 then it means rejected by admin.

1

You create a custom module that will include hook_form_alter(). Something like this:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'article_node_form') {
    global $user;

    if (in_array('admin', array_values($user->roles))) {
      //admin role is not a default role
      //do nothing
    }
    elseif (in_array('authenticated user', array(values($user->roles))) {
      //remove editable field and replace it with a label
      $form['article_field_rejected']['#access'] = FALSE;
      $form['article_field_rejected_label'] = array (
         '#type' => 'item',
         '#default_vale' =>  isset($field['article_field_rejected']['#value']) ? $field['article_field_rejected']['#value'] : '0',
    } 
    else {
     // For everyone else disable field and do not display it
     $form['article_field_rejected']['#access'] = FALSE;
    }     
}

If you don't replace the field with a label, then the use can still alter the value by editing the browser.

| improve this answer | |
1

I assume you're already using the Content permissions module and have only enabled edit field_article_rejected to the appropriate role, let's use content admin.

Now, we're going to use the Rules module to reset the field back to 0 each time the node is saved by a user that does NOT have the content admin role, most likely the owner.

Label: Reset article rejected
Event: Content is going to be saved

Add a condition

Select condition to add: User has role
User: Acting user
Negate: (checked)
Select role(s): content admin

Add an action

Select an action to add: Populate a field
Content: Saved content
Field: field_article_rejected
Article rejected: 0

It only takes 5 minutes to configure a rule. No custom module needed, no code whatsoever. :-)

| improve this answer | |
0

You need to create a custom module that implements hook_form_alter within this you can target your form by $form_id then within that you can use something similar to below:

global $user
if (in_array('registered user', array_values($user->roles)) {
  $form['field_blah'][0]['value'] = 0;
}

Your $form structure may be different.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.