diff options
Diffstat (limited to 'modules/taxonomy')
-rw-r--r-- | modules/taxonomy/taxonomy.admin.inc | 34 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.install | 1 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.pages.inc | 6 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.test | 48 |
4 files changed, 48 insertions, 41 deletions
diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index d83f5d367..a236cfed1 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -209,7 +209,7 @@ function taxonomy_form_vocabulary_validate($form, &$form_state) { * @see taxonomy_form_vocabulary_validate() */ function taxonomy_form_vocabulary_submit($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Delete')) { + if ($form_state['triggering_element']['#value'] == t('Delete')) { // Rebuild the form to confirm vocabulary deletion. $form_state['rebuild'] = TRUE; $form_state['confirm_delete'] = TRUE; @@ -434,7 +434,7 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) { * @see taxonomy_overview_terms() */ function taxonomy_overview_terms_submit($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Reset to alphabetical')) { + if ($form_state['triggering_element']['#value'] == t('Reset to alphabetical')) { // Execute the reset action. if ($form_state['values']['reset_alphabetical'] === TRUE) { return taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, $form_state); @@ -674,9 +674,6 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = if (isset($form_state['confirm_delete'])) { return array_merge($form, taxonomy_term_confirm_delete($form, $form_state, $term->tid)); } - elseif (isset($form_state['confirm_parents'])) { - return array_merge($form, taxonomy_term_confirm_parents($form, $form_state, $vocabulary)); - } $form['name'] = array( '#type' => 'textfield', @@ -801,7 +798,7 @@ function taxonomy_form_term_validate($form, &$form_state) { * @see taxonomy_form_term() */ function taxonomy_form_term_submit($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Delete')) { + if ($form_state['triggering_element']['#value'] == t('Delete')) { // Execute the term deletion. if ($form_state['values']['delete'] === TRUE) { return taxonomy_term_confirm_delete_submit($form, $form_state); @@ -811,12 +808,6 @@ function taxonomy_form_term_submit($form, &$form_state) { $form_state['confirm_delete'] = TRUE; return; } - // Rebuild the form to confirm enabling multiple parents. - elseif ($form_state['clicked_button']['#value'] == t('Save') && count($form_state['values']['parent']) > 1 && $form['#vocabulary']->hierarchy < 2) { - $form_state['rebuild'] = TRUE; - $form_state['confirm_parents'] = TRUE; - return; - } $term = taxonomy_form_term_submit_build_taxonomy_term($form, $form_state); @@ -873,25 +864,6 @@ function taxonomy_form_term_submit_build_taxonomy_term($form, &$form_state) { } /** - * Form builder for the confirmation of multiple term parents. - * - * @ingroup forms - * @see taxonomy_form_term() - */ -function taxonomy_term_confirm_parents($form, &$form_state, $vocabulary) { - foreach (element_children($form_state['values']) as $key) { - $form[$key] = array( - '#type' => 'value', - '#value' => $form_state['values'][$key], - ); - } - $question = t('Set multiple term parents?'); - $description = '<p>' . t("Adding multiple parents to a term will cause the %vocabulary vocabulary to look for multiple parents on every term. Because multiple parents are not supported when using the drag and drop outline interface, drag and drop will be disabled if you enable this option. If you choose to have multiple parents, you will only be able to set parents by using the term edit form.", array('%vocabulary' => $vocabulary->name)) . '</p>'; - $description .= '<p>' . t("You may re-enable the drag and drop interface at any time by reducing multiple parents to a single parent for the terms in this vocabulary.") . '</p>'; - return confirm_form($form, $question, drupal_get_destination(), $description, t('Set multiple parents')); -} - -/** * Form builder for the term delete form. * * @ingroup forms diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 56b7e01c6..68fbc7804 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -438,6 +438,7 @@ function taxonomy_update_7004() { 'entity_type' => 'node', 'settings' => array(), 'description' => $vocabulary->help, + 'required' => $vocabulary->required, 'widget' => array(), 'display' => array( 'default' => array( diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc index 3aed29011..0cca252d7 100644 --- a/modules/taxonomy/taxonomy.pages.inc +++ b/modules/taxonomy/taxonomy.pages.inc @@ -110,7 +110,7 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') { ->execute() ->fetchAllKeyed(); - $prefix = count($tags_typed) ? implode(', ', $tags_typed) . ', ' : ''; + $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : ''; $term_matches = array(); foreach ($tags_return as $tid => $name) { @@ -119,9 +119,7 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') { if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) { $n = '"' . str_replace('"', '""', $name) . '"'; } - else { - $term_matches[$prefix . $n] = check_plain($name); - } + $term_matches[$prefix . $n] = check_plain($name); } } diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 97cfe448f..aa7cc2e44 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -580,7 +580,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { field_create_instance($instance); $terms = array( $this->randomName(), - $this->randomName(), + $this->randomName() . ', ' . $this->randomName(), $this->randomName(), ); @@ -590,7 +590,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $edit["body[$langcode][0][value]"] = $this->randomName(); // Insert the terms in a comma separated list. Vocabulary 1 is a // free-tagging field created by the default profile. - $edit[$instance['field_name'] . "[$langcode]"] = implode(', ', $terms); + $edit[$instance['field_name'] . "[$langcode]"] = drupal_implode_tags($terms); // Preview and verify the terms appear but are not created. $this->drupalPost('node/add/page', $edit, t('Preview')); @@ -611,9 +611,9 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } // Get the created terms. - list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid); + list($term1, $term2, $term3) = array_values(taxonomy_term_load_multiple(FALSE)); - // Delete one term. + // Delete term 1. $this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', array(), t('Delete')); $this->drupalPost(NULL, NULL, t('Delete')); $term_names = array($term2->name, $term3->name); @@ -627,10 +627,17 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } $this->assertNoText($term1->name, t('The deleted term %name does not appear on the node page.', array('%name' => $term1->name))); - // Test autocomplete on term 2. + // Test autocomplete on term 2 - it contains a comma, so expect the key to + // be quoted. $input = substr($term2->name, 0, 3); $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); - $this->assertRaw('{"' . $term2->name . '":"' . $term2->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term2->name))); + $this->assertRaw('{"\"' . $term2->name . '\"":"' . $term2->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term2->name))); + + // Test autocomplete on term 3 - it is alphanumeric only, so no extra + // quoting. + $input = substr($term3->name, 0, 3); + $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); + $this->assertRaw('{"' . $term3->name . '":"' . $term3->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term3->name))); } /** @@ -761,6 +768,35 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Test saving a term with multiple parents through the UI. + */ + function testTermMultipleParentsInterface() { + // Add a new term to the vocabulary so that we can have multiple parents. + $parent = $this->createTerm($this->vocabulary); + + // Add a new term with multiple parents. + $edit = array( + 'name' => $this->randomName(12), + 'description[value]' => $this->randomName(100), + 'parent[]' => array(0, $parent->tid), + ); + // Save the new term. + $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save')); + + // Check that the term was successfully created. + $terms = taxonomy_get_term_by_name($edit['name']); + $term = reset($terms); + $this->assertNotNull($term, t('Term found in database')); + $this->assertEqual($edit['name'], $term->name, t('Term name was successfully saved.')); + $this->assertEqual($edit['description[value]'], $term->description, t('Term description was successfully saved.')); + // Check that the parent tid is still there. The other parent (<root>) is + // not added by taxonomy_get_parents(). + $parents = taxonomy_get_parents($term->tid); + $parent = reset($parents); + $this->assertEqual($edit['parent[]'][1], $parent->tid, t('Term parents were successfully saved.')); + } + + /** * Test taxonomy_get_term_by_name(). */ function testTaxonomyGetTermByName() { |