Commit 0b1ec3bf authored by Dries's avatar Dries
Browse files

- Patch #490182 by amateescu: present all CRUD operations on Taxonomy List terms page.

parent 39b65b36
......@@ -245,13 +245,14 @@ function forum_overview($form, &$form_state) {
if (isset($form[$key]['#term'])) {
$term = $form[$key]['#term'];
$form[$key]['view']['#href'] = 'forum/' . $term['tid'];
unset($form[$key]['operations']['#links']['delete']);
if (in_array($form[$key]['#term']['tid'], variable_get('forum_containers', array()))) {
$form[$key]['edit']['#title'] = t('edit container');
$form[$key]['edit']['#href'] = 'admin/structure/forum/edit/container/' . $term['tid'];
$form[$key]['operations']['#links']['edit']['title'] = t('edit container');
$form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term['tid'];
}
else {
$form[$key]['edit']['#title'] = t('edit forum');
$form[$key]['edit']['#href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];
$form[$key]['operations']['#links']['edit']['title'] = t('edit forum');
$form[$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];
}
}
}
......
......@@ -392,7 +392,15 @@ function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
'#default_value' => $term->weight,
);
}
$form[$key]['edit'] = array('#type' => 'link', '#title' => t('edit'), '#href' => 'taxonomy/term/' . $term->tid . '/edit', '#options' => array('query' => drupal_get_destination()));
$operations = array(
'edit' => array('title' => t('edit'), 'href' => 'taxonomy/term/' . $term->tid . '/edit', 'query' => drupal_get_destination()),
'delete' => array('title' => t('delete'), 'href' => 'taxonomy/term/' . $term->tid . '/delete', 'query' => drupal_get_destination()),
);
$form[$key]['operations'] = array(
'#theme' => 'links',
'#links' => $operations,
'#attributes' => array('class' => array('links', 'inline')),
);
}
$form['#total_entries'] = $total_entries;
......@@ -580,7 +588,7 @@ function theme_taxonomy_overview_terms($variables) {
}
$term['weight']['#attributes']['class'] = array('term-weight');
$row[] = drupal_render($term['weight']);
$row[] = drupal_render($term['edit']);
$row[] = drupal_render($term['operations']);
$row = array('data' => $row);
$rows[$key] = $row;
}
......@@ -671,11 +679,6 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
$form['#term']['parent'] = $parent;
$form['#vocabulary'] = $vocabulary;
// Check for confirmation forms.
if (isset($form_state['confirm_delete'])) {
return array_merge($form, taxonomy_term_confirm_delete($form, $form_state, $term->tid));
}
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
......@@ -768,8 +771,9 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#access' => user_access("delete terms in $vocabulary->vid") || user_access('administer taxonomy'),
'#access' => taxonomy_term_access('delete', $term),
'#weight' => 10,
'#submit' => array('taxonomy_form_term_delete_submit'),
);
}
else {
......@@ -799,17 +803,6 @@ function taxonomy_form_term_validate($form, &$form_state) {
* @see taxonomy_form_term()
*/
function taxonomy_form_term_submit($form, &$form_state) {
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);
}
// Rebuild the form to confirm term deletion.
$form_state['rebuild'] = TRUE;
$form_state['confirm_delete'] = TRUE;
return;
}
$term = taxonomy_form_term_submit_build_taxonomy_term($form, $form_state);
$status = taxonomy_term_save($term);
......@@ -864,19 +857,34 @@ function taxonomy_form_term_submit_build_taxonomy_term($form, &$form_state) {
return $term;
}
/**
* Form submission handler for the 'Delete' button for taxonomy_form_term().
*
* @see taxonomy_form_term_validate()
* @see taxonomy_form_term_submit()
*/
function taxonomy_form_term_delete_submit($form, &$form_state) {
$destination = array();
if (isset($_GET['destination'])) {
$destination = drupal_get_destination();
unset($_GET['destination']);
}
$term = $form['#term'];
$form_state['redirect'] = array('taxonomy/term/' . $term['tid'] . '/delete', array('query' => $destination));
}
/**
* Form builder for the term delete form.
*
* @ingroup forms
* @see taxonomy_term_confirm_delete_submit()
*/
function taxonomy_term_confirm_delete($form, &$form_state, $tid) {
$term = taxonomy_term_load($tid);
function taxonomy_term_confirm_delete($form, &$form_state, $term) {
// Always provide entity id in the same form key as in the entity edit form.
$form['tid'] = array('#type' => 'value', '#value' => $tid);
$form['tid'] = array('#type' => 'value', '#value' => $term->tid);
$form['#term'] = $term;
$form['#vocabulary'] = taxonomy_vocabulary_load($term->vid);;
$form['type'] = array('#type' => 'value', '#value' => 'term');
$form['name'] = array('#type' => 'value', '#value' => $term->name);
$form['vocabulary_machine_name'] = array('#type' => 'value', '#value' => $term->vocabulary_machine_name);
......@@ -900,7 +908,9 @@ function taxonomy_term_confirm_delete_submit($form, &$form_state) {
taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);
drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name'])));
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/taxonomy';
if (!isset($_GET['destination'])) {
$form_state['redirect'] = 'admin/structure/taxonomy';
}
cache_clear_all();
return;
}
......
......@@ -313,12 +313,22 @@ function taxonomy_menu() {
// Pass a NULL argument to ensure that additional path components are not
// passed to taxonomy_form_term() as the vocabulary machine name argument.
'page arguments' => array('taxonomy_form_term', 2, NULL),
'access callback' => 'taxonomy_term_edit_access',
'access arguments' => array(2),
'access callback' => 'taxonomy_term_access',
'access arguments' => array('edit', 2),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'taxonomy.admin.inc',
);
$items['taxonomy/term/%taxonomy_term/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('taxonomy_term_confirm_delete', 2),
'access callback' => 'taxonomy_term_access',
'access arguments' => array('delete', 2),
'type' => MENU_LOCAL_TASK,
'weight' => 11,
'file' => 'taxonomy.admin.inc',
);
$items['taxonomy/term/%taxonomy_term/feed'] = array(
'title' => 'Taxonomy term',
'title callback' => 'taxonomy_term_title',
......@@ -378,15 +388,35 @@ function taxonomy_menu() {
function taxonomy_admin_paths() {
$paths = array(
'taxonomy/term/*/edit' => TRUE,
'taxonomy/term/*/delete' => TRUE,
);
return $paths;
}
/**
* Return edit access for a given term.
* Access callback: Checks a user's permission for performing a taxonomy term
* operation.
*
* @param $op
* The operation to be performed on the taxonomy term. Possible values are:
* - "edit"
* - "delete"
* @param $term
* The $term object on which the operation is to be performed.
*
* @return
* TRUE if the operation may be performed, FALSE otherwise.
*
* @see taxonomy_menu()
*/
function taxonomy_term_edit_access($term) {
return user_access("edit terms in $term->vid") || user_access('administer taxonomy');
function taxonomy_term_access($op, $term) {
if (!$term || !in_array($op, array('edit', 'delete'), TRUE)) {
// If there was no term to check against, or the $op was not one of the
// supported ones, we return access denied.
return FALSE;
}
return user_access("$op terms in $term->vid") || user_access('administer taxonomy');
}
/**
......
......@@ -515,7 +515,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
public static function getInfo() {
return array(
'name' => 'Taxonomy term functions and forms.',
'name' => 'Taxonomy term functions and forms',
'description' => 'Test load, save and delete for taxonomy terms.',
'group' => 'Taxonomy',
);
......@@ -639,8 +639,9 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
field_create_instance($instance);
$terms = array(
'term1' => $this->randomName(),
'term2' => $this->randomName() . ', ' . $this->randomName(),
'term3' => $this->randomName(),
'term2' => $this->randomName(),
'term3' => $this->randomName() . ', ' . $this->randomName(),
'term4' => $this->randomName(),
);
$edit = array();
......@@ -676,31 +677,35 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
$term_objects[$key] = reset($term_objects[$key]);
}
// Delete term 1.
// Delete term 1 from the term edit page.
$this->drupalPost('taxonomy/term/' . $term_objects['term1']->tid . '/edit', array(), t('Delete'));
$this->drupalPost(NULL, NULL, t('Delete'));
$term_names = array($term_objects['term2']->name, $term_objects['term3']->name);
// Delete term 2 from the term delete page.
$this->drupalPost('taxonomy/term/' . $term_objects['term2']->tid . '/delete', array(), t('Delete'));
$term_names = array($term_objects['term3']->name, $term_objects['term4']->name);
// Get the node.
$node = $this->drupalGetNodeByTitle($edit["title"]);
$this->drupalGet('node/' . $node->nid);
foreach ($term_names as $term_name) {
$this->assertText($term_name, t('The term %name appears on the node page after one term %deleted was deleted', array('%name' => $term_name, '%deleted' => $term_objects['term1']->name)));
$this->assertText($term_name, t('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted', array('%name' => $term_name, '%deleted1' => $term_objects['term1']->name, '%deleted2' => $term_objects['term2']->name)));
}
$this->assertNoText($term_objects['term1']->name, t('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term1']->name)));
$this->assertNoText($term_objects['term2']->name, t('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term2']->name)));
// Test autocomplete on term 2, which contains a comma.
// Test autocomplete on term 3, which contains a comma.
// The term will be quoted, and the " will be encoded in unicode (\u0022).
$input = substr($term_objects['term2']->name, 0, 3);
$input = substr($term_objects['term3']->name, 0, 3);
$this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
$this->assertRaw('{"\u0022' . $term_objects['term2']->name . '\u0022":"' . $term_objects['term2']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term2']->name)));
$this->assertRaw('{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
// Test autocomplete on term 3 - it is alphanumeric only, so no extra
// Test autocomplete on term 4 - it is alphanumeric only, so no extra
// quoting.
$input = substr($term_objects['term3']->name, 0, 3);
$input = substr($term_objects['term4']->name, 0, 3);
$this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
$this->assertRaw('{"' . $term_objects['term3']->name . '":"' . $term_objects['term3']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->name)));
$this->assertRaw('{"' . $term_objects['term4']->name . '":"' . $term_objects['term4']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->name)));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment