'disable_term_node_listings_term_page', 'page arguments' => array(2), 'access arguments' => array('access content'), ); } /** * Menu callback; displays all nodes associated with a term. * * @param object $term * The taxonomy term. * * @return string * The page content. */ function disable_term_node_listings_term_page($term) { // Check if the term that this vocabulary belongs to has listings disabled. $disable_status = variable_get('disable_term_node_listings_' . $term->vocabulary_machine_name, 'default'); switch ($disable_status) { case 'hide_listing': // Set the title and return all the field data. drupal_set_title($term->name); return taxonomy_term_view($term, 'full'); break; case '404': return MENU_NOT_FOUND; break; case '403': return MENU_ACCESS_DENIED; break; default: // We have to pull in taxonomy's pages include to call its function. module_load_include('inc', 'taxonomy', 'taxonomy.pages'); return taxonomy_term_page($term); break; } } /** * Implements hook_form_alter(). * * Used to add toggle checkbox to the vocabulary edit pages. */ function disable_term_node_listings_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'taxonomy_form_vocabulary' && !isset($form_state['confirm_delete'])) { $vocab_machine_name = $form['#vocabulary']->machine_name; $disable_status = variable_get('disable_term_node_listings_' . $vocab_machine_name, 'default'); // Status toggle switch. $form['disable_term_node_listings_status'] = array( '#type' => 'radios', '#weight' => 3, '#title' => t('Node listings'), '#description' => t('This field controls the display of all terms in this vocabulary.'), '#default_value' => $disable_status, '#options' => array( 'default' => t('Use default node listings'), 'hide_listing' => t('Disable node listing for all terms'), '404' => t('Display 404 page'), '403' => t('Display 403 page'), ), ); $form['#submit'][] = '_disable_term_node_listings_submit_handler'; } } /** * Save the status of the taxonomy term to the database. */ function _disable_term_node_listings_submit_handler($form, &$form_state) { // Machine name is not available when we are deleting a term // so don't try to save the variable. if (isset($form_state['values']['machine_name'])) { $vocab_machine_name = $form_state['values']['machine_name']; // Store the status of this vocabulary based on user input. $disable_status = $form_state['values']['disable_term_node_listings_status']; variable_set('disable_term_node_listings_' . $vocab_machine_name, $disable_status); } } /** * Implements hook_taxonomy_vocabulary_delete(). */ function disable_term_node_listings_taxonomy_vocabulary_delete($vocabulary) { // If the vocabulary gets deleted, clean up our variable as well. variable_del('disable_term_node_listings_' . $vocabulary->machine_name); } /** * Implements hook_taxonomy_vocabulary_update(). */ function disable_term_node_listings_taxonomy_vocabulary_update($vocabulary) { // If the vocabulary machine name changed // delete the variable associated with the old name. if ($vocabulary->old_machine_name != $vocabulary->machine_name) { variable_del('disable_term_node_listings_' . $vocabulary->old_machine_name); } }