Index: taxonomy_block.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_block/taxonomy_block.module,v retrieving revision 1.14 diff -u -r1.14 taxonomy_block.module --- taxonomy_block.module 31 Jan 2006 15:00:56 -0000 1.14 +++ taxonomy_block.module 16 Jan 2007 17:00:54 -0000 @@ -2,17 +2,6 @@ // $Id: taxonomy_block.module,v 1.14 2006/01/31 15:00:56 budda Exp $ /** - * Implementation of hook_help. - */ -function taxonomy_block_help($section) { - switch ($section) { - case 'admin/modules#description' : - return t('Makes blocks based on taxonomy vocabularies and terms.'); - break; - } -} - -/** * Implementation of hook_perm. */ function taxonomy_block_perm() { @@ -26,8 +15,41 @@ $items = array(); if ($may_cache) { - $items[] = array('path' => 'admin/block/taxonomy_block', 'title' => t('taxonomy block'), 'callback' => 'taxonomy_block_admin', 'access' => user_access('administer taxonomy blocks')); - $items[] = array('path' => 'admin/block/taxonomy_block/edit', 'title' => t('edit taxonomy block'), 'callback' => 'taxonomy_block_form', 'access' => user_access('administer taxonomy blocks'), 'type' => MENU_CALLBACK); + $items[] = array( + 'path' => 'admin/build/taxonomy-block', + 'title' => t('Taxonomy Blocks'), + 'description' => t('Configure how taxonomy blocks are displayed.'), + 'callback' => 'taxonomy_block_overview', + 'access' => user_access('administer taxonomy blocks'), + ); + $items[] = array( + 'path' => 'admin/build/taxonomy-block/list', + 'title' => t('List'), + 'callback' => 'taxonomy_block_overview', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + $items[] = array( + 'path' => 'admin/build/taxonomy-block/add', + 'title' => t('Add'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('taxonomy_block_form'), + 'type' => MENU_LOCAL_TASK, + ); + $items[] = array( + 'path' => 'admin/build/taxonomy-block/edit', + 'title' => t('Edit Taxonomy Block'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('taxonomy_block_form'), + 'type' => MENU_CALLBACK, + ); + $items[] = array( + 'path' => 'admin/build/taxonomy-block/delete', + 'title' => t('Delete Taxonomy Block'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('taxonomy_block_delete_form'), + 'type' => MENU_CALLBACK, + ); } return $items; @@ -48,27 +70,24 @@ } /** - * Displays the administrator page to this module. + * Displays block delete confirmation form. */ -function taxonomy_block_admin($op = NULL, $bid = NULL) { - switch ($op) { - case 'delete' : - $form['bid'] = array( - '#type' => 'hidden', - '#value' => $bid, - ); - $output = confirm_form('taxonomy_block_delete_form', $form, t('Are you sure you want to delete the taxonomy block?'), 'admin/block/taxonomy_block'); - break; - default: - $output = taxonomy_block_blocks(); - $output .= taxonomy_block_form(); - break; - } - - drupal_set_title(t('Taxonomy Block Administration')); - return $output; +function taxonomy_block_delete_form($bid){ + $form['bid'] = array( + '#type' => 'value', + '#value' => $bid, + ); + return confirm_form( + $form, + t('Are you sure you want to delete the taxonomy block?'), + 'admin/build/taxonomy-block', + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') + ); } + /** * Inserts a block into the database. */ @@ -94,69 +113,60 @@ db_query('DELETE FROM {taxonomy_block} WHERE bid = %d', $bid); } + /** -* Displays the block creation form. -*/ + * Generates the block creation form. + */ function taxonomy_block_form($bid = NULL) { if ($bid) { $block = db_fetch_object(db_query('SELECT * FROM {taxonomy_block} WHERE bid = %d', $bid)); } - $form['create_taxonomy_block'] = array( - '#type' => 'fieldset', - '#title' => t('Create Block'), - ); - $form['create_taxonomy_block']['bid'] = array( - '#type' => 'hidden', + $form['bid'] = array( + '#type' => 'value', '#value' => $bid, ); - $form['create_taxonomy_block']['name'] = array( + $form['name'] = array( '#type' => 'textfield', '#title' => t('Block Name'), '#default_value' => $block->name, '#description' => t('This is the name of your block.'), - ); - $form['create_taxonomy_block']['description'] = array( + ); + $form['description'] = array( '#type' => 'textfield', '#title' => t('Block Description'), '#default_value' => $block->description, '#description' => t('This is the description of your block. It is not displayed to users.'), '#required' => TRUE, - ); - $form['create_taxonomy_block']['teaser'] = array( + ); + $form['teaser'] = array( '#type' => 'textfield', '#title' => t('Teaser Length'), '#default_value' => $block->teaser, '#description' => t('This is the length of node body content to display under each title in characters. Leave blank for none.'), - ); - $form['create_taxonomy_block']['length'] = array( + ); + $form['length'] = array( '#type' => 'textfield', '#title' => t('Node Count'), '#default_value' => $block->length, '#description' => t('This is the number of nodes to display.'), '#required' => TRUE, - ); + ); - $form['create_taxonomy_block']['tid'] = _taxonomy_block_get_taxonomy_dropdown($block->type == 'vocabulary' ? 'v'. $block->tid : $block->tid); + $form['tid'] = _taxonomy_block_get_taxonomy_dropdown($block->type == 'vocabulary' ? 'v'. $block->tid : $block->tid); + $form[] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); if($bid) { - $form['create_taxonomy_block'][] = array( - '#type' => 'submit', - '#value' => t('Edit Block'), - ); - $form['create_taxonomy_block'][] = array( + $form[] = array( '#type' => 'submit', '#value' => t('Cancel'), - ); - } - else { - $form['create_taxonomy_block'][] = array( - '#type' => 'submit', - '#value' => t('Create Block'), - ); + ); } - return drupal_get_form('taxonomy_block_form', $form); + return $form; } /** @@ -166,7 +176,7 @@ if(!$edit['description']) { form_set_error('description', t('Please provide a description for your block. It will be used in administration screens only.')); } - if($edit['length'] <=0) { + if($edit['length'] <= 0) { form_set_error('length', t('Please provide a node count greater than 0.')); } if(!$edit['tid']) { @@ -177,9 +187,9 @@ * taxonomy_block_form form execute callback function. */ function taxonomy_block_form_submit($form_id, $edit) { - $op = $_POST['op']; + $op = $edit['op']; - if(substr($edit['tid'], 0, 1)=='v') { + if(substr($edit['tid'], 0, 1) == 'v') { $edit['type'] = 'vocabulary'; $edit['tid'] = substr($edit['tid'], 1); } @@ -193,34 +203,43 @@ elseif($op == t('Edit Block')) { taxonomy_block_update($edit); } - drupal_goto('admin/block/taxonomy_block'); + return 'admin/build/taxonomy-block'; } function taxonomy_block_delete_form_submit($form_id, $edit) { taxonomy_block_delete($edit['bid']); + // Not sure if it is really needed - maybe it is too drastic! + cache_clear_all(); drupal_set_message(t('The block has been deleted.')); - drupal_goto('admin/block/taxonomy_block'); + return 'admin/build/taxonomy-block'; } /** * Displays a list of the blocks. */ -function taxonomy_block_blocks() { +function taxonomy_block_overview() { + $blocks = array(); $result = db_query('SELECT * FROM {taxonomy_block}'); while ($block = db_fetch_object($result)) { - $links = array(); - $links[] = l(t('edit'), 'admin/block/taxonomy_block/edit/'. $block->bid, array('title'=>t('edit block')));; - $links[] = l(t('delete'), 'admin/block/taxonomy_block/delete/'. $block->bid, array('title'=>t('delete block')));; + $links = array( + 'edit' => array( + 'title'=>t('edit block'), + 'href' => 'admin/build/taxonomy-block/edit/'. $block->bid, + ), + 'delete' => array( + 'title'=>t('delete'), + 'href' => 'admin/build/taxonomy-block/delete/'. $block->bid, + ), + ); $blocks[] = $block->description .' - '. theme('links', $links); } - $form['show_taxonomy_block'][] = array( - '#type' => 'fieldset', - '#title' => t('Current Blocks'), - '#value' => theme('item_list', $blocks), - ); - - return drupal_get_form('taxonomy_block_admin', $form); + if ($blocks) { + return theme('item_list', $blocks); + } + else { + return t("There are no taxonomy blocks."); + } } /** @@ -293,7 +312,7 @@ '#options' => $links, '#description' => t('Select taxonomy type to display'), '#required' => TRUE, - ); + ); } /** @@ -319,4 +338,3 @@ return $output; } -?>