1

I have some content that has state field. I would like to permit users with the same state to delete this content.
Can I implement this in Drupal?
Can I implement it with PHP code?

1

custom.info

PS. Do not include <?php ?> tags.

; $Id:
name = Custom
description = Custom validate node delete permission
package = Custom
core = 6.x

custom.module

  <?php
    /*
     * file
     */
    function MYMODULE_form_alter(&$form, &$form_state< $form_id){
      switch($form_id){
        case 'node_delete_confirm':
          $form['#validate'][] = 'my_custom_validate';
          break;
      }
    }

    function my_custom_validate($form, &$form_state){
      $nid = $form_state['values']['nid'];
      $node = node_load($nid);
      if(/* conditions */) {
        // some procedure to check fields
        $message = t('You have not any permission to delete this node!');
        form_set_error('nid', $message);
      }
    }
  ?>

Place this files into /sites/all/modules/custom/*.* and activate it on module administration page. Enjoy.

4
  • thank you for drupal code. but i am not familiar with writing module . can i implement it by php code and delete node with sql.? – user780 Apr 10 '11 at 8:47
  • New code has been added – dobeerman Apr 10 '11 at 10:29
  • It's wrong to add a "version" line in .info files; Drupal core modules use such line, but third-party modules should not use it. – apaderno Apr 10 '11 at 12:20
  • for sure. I'm forget to delete this line – dobeerman Apr 10 '11 at 21:51

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.