diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 96ef32f1588553549a6866ea12d17bfb276aed52..97f1300c3d4d8b707b143b4ba97c4978260f74d2 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -275,17 +275,23 @@ function taxonomy_form_term(&$form_state, $vocabulary, $edit = array()) { '#collapsed' => TRUE, ); - $parent = array_keys(taxonomy_get_parents($edit['tid'])); - $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']); + // taxonomy_get_tree and taxonomy_get_parents may contain large numbers of + // items so we check for taxonomy_override_selector before loading the + // full vocabulary. Contrib modules can then intercept before + // hook_form_alter to provide scalable alternatives. + if (!variable_get('taxonomy_override_selector', FALSE)) { + $parent = array_keys(taxonomy_get_parents($edit['tid'])); + $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']); + + // A term can't be the child of itself, nor of its children. + foreach ($children as $child) { + $exclude[] = $child->tid; + } + $exclude[] = $edit['tid']; - // A term can't be the child of itself, nor of its children. - foreach ($children as $child) { - $exclude[] = $child->tid; + $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') .'.', 1, '<'. t('root') .'>', $exclude); + $form['advanced']['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary->vid, NULL, 1, '<'. t('none') .'>', array($edit['tid'])); } - $exclude[] = $edit['tid']; - - $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') .'.', 1, '<'. t('root') .'>', $exclude); - $form['advanced']['synonyms'] = array( '#type' => 'textarea', '#title' => t('Synonyms'), diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 1b8e7e10d889d6742880e14cfa0eb2fd9bf75c5e..dbb3c057e4a072071f8e470cdda5c0e145795813 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -428,9 +428,12 @@ function taxonomy_get_vocabularies($type = NULL) { /** * Implementation of hook_form_alter(). * Generate a form for selecting terms to associate with a node. + * We check for taxonomy_override_selector before loading the full + * vocabulary, so contrib modules can intercept before hook_form_alter + * and provide scalable alternatives. */ function taxonomy_form_alter(&$form, $form_state, $form_id) { - if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) { + if (isset($form['type']) && isset($form['#node']) && (!variable_get('taxonomy_override_selector', FALSE)) && $form['type']['#value'] .'_node_form' == $form_id) { $node = $form['#node']; if (!isset($node->taxonomy)) {