1. That is what I would like to prevent. Deleting the children when parent term is deleted.

I'm currently building an e-commerce website which requires multi level category, so I have to use the function taxonomy_get_children() to be able to get the children. I've disabled the button and set a message to delete the child first before deleting the parent term if the parent term has children. I've used taxonomy_select_nodes() from your code to check if there's a node attached to it. That is the easiest way for me. Please check below to check my code. I have removed loading the nodes and just added in the instruction to see the list of nodes in the view tab to prevent too much memory usage though you've set a limit already.

2. Thank you for explaining that to me. That was explained well. Thank you.

Here is my code:
function mymodule_form_taxonomy_form_term_alter(&$form, &$form_state) {
// Checking if we are on the delete confirmation form.
if (isset($form['delete'])) {

// Getting the term id.
$tid = $form['#term']->tid;

// Check if term has children
$children = taxonomy_get_children($tid);
if(count($children) > 0) {
drupal_set_message(t("This term has children and cannot be deleted until the children of this term has been deleted."), 'error');
$form['description']['#markup'] = '';
$form['actions']['submit']['#disabled'] = TRUE;
}

// Getting node ids referencing this term.
$results = taxonomy_select_nodes($tid, FALSE);
if (count($results) > 0 && !empty($results)) {
drupal_set_message(t("This term is being used and cannot be deleted. Please remove this taxonomy term from the node first."), 'error');
$form['description']['#markup'] = 'Click the view tab to be able to see the list of nodes.';
$form['actions']['submit']['#disabled'] = TRUE;
}
}
}

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Restricted HTML

  • Zulässige HTML-Tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <pre> <ul type> <ol start type> <li> <dl> <dt> <dd> <h4 id> <h5 id> <h6 id>
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.

Angebot innerhalb von 24 Stunden

Ob ein großes kommerzielles System, oder eine kleine Business Seite, wir schicken ein Angebot ab innerhalb von 24 Stunden nachdem Sie diese Taste drücken: Angebot anfordern