name); } elseif (is_object($root)) { drupal_set_title($root->name); } elseif (is_numeric($root)) { $query = db_select('taxonomy_term_data', 'foo'); $query->addField('foo', 'name'); $query->condition('foo.tid', $root); $name = $query->execute()->fetchField(); drupal_set_title($name); } if (is_object($root)) { $root = $root->tid; } if (!isset($vocabulary)) { // It means we are not in administrative pages. $in_page = TRUE; $query = db_select('taxonomy_term_data', 'foo'); $query->addField('foo', 'vid'); $query->condition('foo.tid', $root); $vid = $query->execute()->fetchField(); $vocabulary = taxonomy_vocabulary_load($vid); } // Make sure Drupal Ajax framework javascript is around. drupal_add_library('system', 'drupal.ajax'); if (isset($form_state['confirm_term_delete'])) { // Show term confirmation deletion form. return taxonomy_tools_confirm_term_delete($form, $form_state, $vocabulary, $root); } $form = array(); $form['#attached']['js'][] = drupal_get_path('module', 'taxonomy_tools') . '/js/taxonomy_tools.js'; $form['#attached']['css'][] = drupal_get_path('module', 'taxonomy_tools') . '/style/taxonomy_tools.css'; $form['#vocabulary'] = $vocabulary; // Link for adding new term. $href = ''; $destination = drupal_get_destination(); $href = $destination['destination'] . '/add'; if (is_numeric(strpos($destination['destination'], 'taxonomy/term'))) { $href .= '/' . $vocabulary->machine_name; } $form['add_term'] = array( '#type' => 'link', '#title' => t('Add term'), '#href' => $href, '#attributes' => array( 'title' => t('Add term'), ), '#options' => array( 'query' => array( 'destination' => $destination['destination'], ), ), '#access' => taxonomy_tools_overview_access($vocabulary, TRUE), ); if ($root) { // Link to move up the term hierarchy. $href = ''; $query = db_select('taxonomy_term_hierarchy', 'foo'); $query->addField('foo', 'parent'); $query->condition('foo.tid', $root); $parent = $query->execute()->fetchField(); if (($in_page && $parent > 0) || !$in_page) { // Correct href depending on wether we are in administrative // pages or not. if ($in_page) { $href = 'taxonomy/term/' . $parent . '/overview'; } else { $href = 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/overview'; if ($parent > 0) { $href .= '/' . $parent; } } $form['level_up'] = array( '#type' => 'link', '#title' => t('Up one level'), '#href' => $href, '#attributes' => array( 'title' => t('Up one level'), ), ); } } // Fetch all the necessary information from the database. $query = db_select('taxonomy_term_data', 'db1'); $query->addField('db1', 'tid'); $query->addField('db1', 'name'); $query->addField('db1', 'weight'); $query->condition('db1.vid', $vocabulary->vid); $query->join('taxonomy_term_hierarchy', 'db2', 'db1.tid = db2.tid'); if (!$root) { $root = 0; } $query->condition('db2.parent', $root); if (module_exists('taxonomy_tools_publisher')) { $config = variable_get('taxonomy_tools_publisher_config', array()); if (!empty($config) && in_array($vocabulary->vid, $config)) { $query->leftJoin('field_data_field_taxonomy_term_status', 'db3', 'db1.tid = db3.entity_id'); $query->addField('db3', 'field_taxonomy_term_status_value', 'status'); $query->leftJoin('field_data_field_taxonomy_term_publish_on', 'db4', 'db1.tid = db4.entity_id'); $query->addField('db4', 'field_taxonomy_term_publish_on_value', 'publish_on'); $query->leftJoin('field_data_field_taxonomy_term_unpublish_on', 'db5', 'db1.tid = db5.entity_id'); $query->addField('db5', 'field_taxonomy_term_unpublish_on_value', 'unpublish_on'); } } $query->orderBy('db1.weight'); $query->orderBy('db1.name'); $result = $query->execute()->fetchAll(); $length = sizeof($result); $i = 1; $form['tree_root'] = array( '#type' => 'hidden', '#value' => $root, ); foreach ($result as $term) { $form[$term->tid] = array(); // Term name. $href = ''; if (arg(3) == 'overview') { $href = 'taxonomy/term/' . $term->tid . '/overview'; } else { $href = 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/overview/' . $term->tid; } $form[$term->tid]['name'] = array( '#type' => 'link', '#title' => $term->name, '#href' => $href, ); // Term children count. $query = db_select('taxonomy_term_hierarchy', 'foo'); $query->addField('foo', 'tid'); $query->condition('foo.parent', $term->tid); $child_count = $query->countQuery()->execute()->fetchField(); $form[$term->tid]['child_count'] = array( '#markup' => '' . $child_count . '', ); // Informative icons. $icons = module_invoke_all('taxonomy_tools_overview_info_icons', $term->tid); foreach ($icons as $key => $icon) { $form[$term->tid]['info_icons'][$key] = array( '#markup' => theme_image($icon), ); } // Term weight. $form[$term->tid]['weight_' . $term->tid] = array( '#type' => 'weight', '#delta' => $length, '#title_display' => 'invisible', '#title' => t('Weight for added term'), '#default_value' => $term->weight, '#access' => (user_access('administer taxonomy') || user_access('edit terms in ' . $vocabulary->vid)), ); // View link. $form[$term->tid]['operations'] = array(); $view_link = 'taxonomy/term/' . $term->tid; $form[$term->tid]['operations']['view'] = array( '#type' => 'link', '#title' => '', '#href' => $view_link, '#attributes' => array( 'class' => array( 'view-term', ), 'title' => t('view'), ), ); // Edit link. $edit_link = 'taxonomy/term/' . $term->tid . '/edit'; $destination = drupal_get_destination(); $form[$term->tid]['operations']['edit'] = array( '#type' => 'link', '#title' => '', '#href' => $edit_link, '#attributes' => array( 'class' => array( 'edit-term', ), 'title' => t('edit'), ), '#options' => array( 'query' => array( 'destination' => $destination['destination'], ), ), '#access' => (user_access('administer taxonomy') || user_access('edit terms in ' . $vocabulary->vid)), ); // Any other operation links added by other modules. $additional_links = module_invoke_all('taxonomy_tools_overview_links', $term->tid); foreach ($additional_links as $key => $link) { $form[$term->tid]['operations'][$key] = $link; } // Deletion checkbox. $form[$term->tid]['delete_' . $term->tid] = array( '#type' => 'checkbox', '#title' => t('delete'), '#title_display' => 'invisible', '#access' => (user_access('administer taxonomy') || user_access('delete terms in ' . $vocabulary->vid)), ); if (module_exists('taxonomy_tools_publisher')) { // Publishing status. if (!isset($term->status) || $term->status == 1) { $status = t('Published.'); if (isset($term->unpublish_on)) { $status .= ' '; $status .= t('Will be unpublished on :date', array( ':date' => format_date($term->unpublish_on, 'custom', TAXONOMY_PUBLISHER_MESSAGE_DATE_FORMAT)) ); } } else { $status = t('Unpublished.'); if (isset($term->publish_on)) { $status .= ' '; $status .= t('Will be published on :date.', array( ':date' => format_date($term->publish_on, 'custom', TAXONOMY_PUBLISHER_MESSAGE_DATE_FORMAT)) ); } if (isset($term->unpublish_on)) { $status .= ' '; $status .= t('Will be unpublished on :date.', array( ':date' => format_date($term->unpublish_on, 'custom', TAXONOMY_PUBLISHER_MESSAGE_DATE_FORMAT)) ); } } $form[$term->tid]['status'] = array( '#markup' => $status, ); } if (module_exists('taxonomy_tools_role_access')) { // Buttons for changing term access for user roles. $config = variable_get('taxonomy_tools_role_access_vocab_config', array()); if (!empty($config) && in_array($vocabulary->vid, $config)) { $config = variable_get('taxonomy_tools_role_access_role_config', array()); if (!empty($config)) { $roles = user_roles(); // User role "authenticated user" is not used when other custom // created user roles exist. if (sizeof($roles) > 2) { unset($roles[2]); } foreach ($roles as $rid => $role) { if (in_array($rid, $config)) { $access = taxonomy_tools_role_access_get_access($term->tid, $rid); $attributes = array( 'class' => array( 'use-ajax', 'access_' . $term->tid . '_' . $rid, ), 'title' => t('change'), ); if ($access) { $attributes['class'][] = 'true'; } else { $attributes['class'][] = 'false'; } $opposite = $access ? 'false' : 'true'; $link = 'taxonomy-role-access/nojs/' . $vocabulary->machine_name . '/' . $term->tid . '/' . $rid . '/' . $opposite; if ($root > 0) { $link .= '/' . $root; } $form[$term->tid]['access'][$role] = array( '#type' => 'link', '#title' => '', '#href' => $link, '#attributes' => $attributes, '#access' => user_access('administer taxonomy role access'), ); } } } } } $i++; } $description = t('The number of child taxonomy terms is displayed next to the taxonomy term name. If the current overview page location is other than root level, the first row of the table will display a link with the functionality to go up one level.'); $form['description'] = array( '#markup' => '