0
votes

As explain in the title I'm looking for delete a node when there is an empty field required. I don't know very well Drupal so please can you give me some advice for resolve my problem ? Do I have to develop a new module? or just modify some lines in an existing module?

Thanks in advance for your answers

2

2 Answers

0
votes

If you have already given the field as required then you will not be able to create the node with empty field, so no need to do any other code to delete.

If not made as required then do the following,

Just make the field as required form back-end.

  1. Go to admin->structure->content types

  2. Click on manage fields on your specified content type,

  3. Edit your required field

  4. Check the "Required field" in the edit page of that field and save

Its all done, it will restrict submitting the form with the field empty.

0
votes

This is the first Google result for "drupal can't delete node with empty required field," and it seems the OP is having my exact problem, so I am posting my solution here. No other results on Google gave me a solution to my problem.

In order to recreate this issue in e.g. a vanilla Drupal install, make a field in a content type required, such as the Body. Create a node of that content type. Then try to delete that node after removing all content from the Body. Drupal doesn't let you do it because it always validates form #submit elements unless you tell it not to. This is a problem if e.g. nodes are programmatically created with a lot of required fields empty.

/**
 * Implements hook_form_alter()
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form_id)) {
    if ($form_id == 'NODETYPE_node_form') {
      $form['actions']['fdelete'] = array(
        '#type' => 'submit',
        '#weight' => 999,
        '#access' => user_has_role(user_role_load_by_name('administrator')->rid),
        '#value' => t('Force Delete'),
        '#submit' => array('mymodule_force_delete'),
        '#limit_validation_errors' => array(),
      );  
    }   
  }
}

function mymodule_force_delete(&$form, &$form_state) {
  unset($_GET['destination']);
  drupal_goto("node/{$form_state['node']->nid}/delete");
}

This solution works because node/%/delete is just a prompt to delete the node without triggering any validation of the node content.