summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2011-12-23 03:42:04 (GMT)
committercatch2011-12-23 03:42:04 (GMT)
commitb100374e3c91e3c1c167c84cd8b5fc9e02edeea0 (patch)
treea7f3d498dedfacd621a6888f66192fa3a9143d4d
parent0f3b394f11fee15778fa0197d2d413f36644bd29 (diff)
Issue #1369200 by chris.leversuch, acouch: Define constants for taxonomy hierarchy.
-rw-r--r--core/modules/taxonomy/taxonomy.admin.inc21
-rw-r--r--core/modules/taxonomy/taxonomy.module36
2 files changed, 37 insertions, 20 deletions
diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc
index 99114a6..8541b78 100644
--- a/core/modules/taxonomy/taxonomy.admin.inc
+++ b/core/modules/taxonomy/taxonomy.admin.inc
@@ -115,7 +115,7 @@ function taxonomy_form_vocabulary($form, &$form_state, $edit = array()) {
'name' => '',
'machine_name' => '',
'description' => '',
- 'hierarchy' => 0,
+ 'hierarchy' => TAXONOMY_HIERARCHY_DISABLED,
'weight' => 0,
);
foreach ($defaults as $key => $value) {
@@ -368,7 +368,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
}
$form[$key]['view'] = array('#type' => 'link', '#title' => $term->name, '#href' => "taxonomy/term/$term->tid");
- if ($vocabulary->hierarchy < 2 && count($tree) > 1) {
+ if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
$form['#parent_fields'] = TRUE;
$form[$key]['tid'] = array(
'#type' => 'hidden',
@@ -402,7 +402,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
$form['#forward_step'] = $forward_step;
$form['#empty_text'] = t('No terms available. <a href="@link">Add term</a>.', array('@link' => url('admin/structure/taxonomy/' . $vocabulary->machine_name . '/add')));
- if ($vocabulary->hierarchy < 2 && count($tree) > 1) {
+ if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
$form['actions'] = array('#type' => 'actions', '#tree' => FALSE);
$form['actions']['submit'] = array(
'#type' => 'submit',
@@ -449,7 +449,8 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
uasort($form_state['values'], 'drupal_sort_weight');
$vocabulary = $form['#vocabulary'];
- $hierarchy = 0; // Update the current hierarchy type as we go.
+ // Update the current hierarchy type as we go.
+ $hierarchy = TAXONOMY_HIERARCHY_DISABLED;
$changed_terms = array();
$tree = taxonomy_get_tree($vocabulary->vid);
@@ -468,7 +469,7 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
$changed_terms[$term['tid']] = $term;
}
$weight++;
- $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;
+ $hierarchy = $term['parents'][0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
$term = (array) $tree[$weight];
}
@@ -495,7 +496,7 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
$term['parent'] = $values['parent'];
$changed_terms[$term['tid']] = $term;
}
- $hierarchy = $term['parent'] != 0 ? 1 : $hierarchy;
+ $hierarchy = $term['parent'] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
$weight++;
}
}
@@ -508,7 +509,7 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
$term['weight'] = $weight;
$changed_terms[$term['tid']] = $term;
}
- $hierarchy = $term['parents'][0] != 0 ? 1 : $hierarchy;
+ $hierarchy = $term['parents'][0] != 0 ? TAXONOMY_HIERARCHY_SINGLE : $hierarchy;
}
// Save all updated terms.
@@ -702,7 +703,7 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
'#type' => 'fieldset',
'#title' => t('Relations'),
'#collapsible' => TRUE,
- '#collapsed' => $vocabulary->hierarchy < 2,
+ '#collapsed' => ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE),
'#weight' => 10,
);
@@ -840,8 +841,8 @@ function taxonomy_form_term_submit($form, &$form_state) {
}
// If we've increased the number of parents and this is a single or flat
// hierarchy, update the vocabulary immediately.
- elseif ($current_parent_count > $previous_parent_count && $form['#vocabulary']->hierarchy < 2) {
- $form['#vocabulary']->hierarchy = $current_parent_count == 1 ? 1 : 2;
+ elseif ($current_parent_count > $previous_parent_count && $form['#vocabulary']->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE) {
+ $form['#vocabulary']->hierarchy = $current_parent_count == 1 ? TAXONOMY_HIERARCHY_SINGLE : TAXONOMY_HIERARCHY_MULTIPLE;
taxonomy_vocabulary_save($form['#vocabulary']);
}
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 191b519..c495a1e 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -6,6 +6,21 @@
*/
/**
+ * Denotes that no term in the vocabulary has a parent.
+ */
+const TAXONOMY_HIERARCHY_DISABLED = 0;
+
+/**
+ * Denotes that one or more terms in the vocabulary has a single parent.
+ */
+const TAXONOMY_HIERARCHY_SINGLE = 1;
+
+/**
+ * Denotes that one or more terms in the vocabulary have multiple parents.
+ */
+const TAXONOMY_HIERARCHY_MULTIPLE = 2;
+
+/**
* Users can create new terms in a free-tagging vocabulary when
* submitting a taxonomy_autocomplete_widget. We store a term object
* whose tid is 'autocreate' as a field data item during widget
@@ -51,11 +66,11 @@ function taxonomy_help($path, $arg) {
case 'admin/structure/taxonomy/%':
$vocabulary = taxonomy_vocabulary_machine_name_load($arg[3]);
switch ($vocabulary->hierarchy) {
- case 0:
+ case TAXONOMY_HIERARCHY_DISABLED:
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '</p>';
- case 1:
+ case TAXONOMY_HIERARCHY_SINGLE:
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '</p>';
- case 2:
+ case TAXONOMY_HIERARCHY_MULTIPLE:
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', array('%capital_name' => drupal_ucfirst($vocabulary->name))) . '</p>';
}
}
@@ -519,10 +534,11 @@ function taxonomy_taxonomy_vocabulary_update($vocabulary) {
*
* Checks the current parents of all terms in a vocabulary and updates the
* vocabulary's hierarchy setting to the lowest possible level. If no term
- * has parent terms then the vocabulary will be given a hierarchy of 0.
- * If any term has a single parent then the vocabulary will be given a
- * hierarchy of 1. If any term has multiple parents then the vocabulary
- * will be given a hierarchy of 2.
+ * has parent terms then the vocabulary will be given a hierarchy of
+ * TAXONOMY_HIERARCHY_DISABLED. If any term has a single parent then the
+ * vocabulary will be given a hierarchy of TAXONOMY_HIERARCHY_SINGLE. If any
+ * term has multiple parents then the vocabulary will be given a hierarchy of
+ * TAXONOMY_HIERARCHY_MULTIPLE.
*
* @param $vocabulary
* A vocabulary object.
@@ -534,7 +550,7 @@ function taxonomy_taxonomy_vocabulary_update($vocabulary) {
*/
function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
$tree = taxonomy_get_tree($vocabulary->vid);
- $hierarchy = 0;
+ $hierarchy = TAXONOMY_HIERARCHY_DISABLED;
foreach ($tree as $term) {
// Update the changed term with the new parent value before comparison.
if ($term->tid == $changed_term['tid']) {
@@ -543,11 +559,11 @@ function taxonomy_check_vocabulary_hierarchy($vocabulary, $changed_term) {
}
// Check this term's parent count.
if (count($term->parents) > 1) {
- $hierarchy = 2;
+ $hierarchy = TAXONOMY_HIERARCHY_MULTIPLE;
break;
}
elseif (count($term->parents) == 1 && 0 !== array_shift($term->parents)) {
- $hierarchy = 1;
+ $hierarchy = TAXONOMY_HIERARCHY_SINGLE;
}
}
if ($hierarchy != $vocabulary->hierarchy) {