Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top