Note: Requires content.module.'); } } /** * Implementation of hook_field_info(). */ function fieldtaxonomy_field_info() { return array( 'fieldtaxonomy' => array('label' => 'Taxonomy block'), ); } /** * Implementation of hook_field_settings(). */ function fieldtaxonomy_field_settings($op, $field) { switch ($op) { case 'form': $form = array(); $options = array ( 'yes' => t('Yes'), 'no' => t('No'), ); $form['teasers'] = array( '#type' => 'radios', '#title' => t('Generate teasers'), '#default_value' => isset($field['teasers']) ? $field['teasers'] : 'yes', '#options' => $options, ); $form['nodecount'] = array( '#type' => 'textfield', '#title' => t('Amount to show'), '#default_value' => $field['nodecount'] ? $field['nodecount'] : '10', '#description' => t('The number of nodes to show.'), ); return $form; case 'save': return array('teasers','nodecount'); case 'database columns': return array( 'teasers' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"), 'nodecount' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"), 'fieldtaxonomy' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => "''"), ); } } /** * Implementation of hook_field(). */ function fieldtaxonomy_field($op, &$node, $field, &$items, $teaser, $page) { switch ($op) { case 'view': foreach ($items as $delta => $item) { $items[$delta]['view'] = _my_fieldtaxonomy($items[$delta]['fieldtaxonomy'],$field); } return theme('field', $node, $field, $items, $teaser, $page); break; } } function _my_fieldtaxonomy($tid,$field) { $tid = $tid; $length = $field['nodecount']; if ($field['teasers']=='yes'){ $teas = 1; } if (is_numeric($tid)){ // if ($conf->type == 'term') { $tids = taxonomy_get_children($tid); $tids[$tid] = $tid; // } // else {*/ // $tids = taxonomy_get_children(0, $conf['create_taxonomy_block']['tid']); // } $nodes = db_query(db_rewrite_sql('SELECT DISTINCT(n.nid), n.title, r.body, r.teaser, sticky, created FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE t.tid IN (%s) AND n.status = 1 ORDER BY sticky DESC, created DESC LIMIT %d'), implode(array_keys($tids), ','), $length); $block['subject'] = $description; while ($node = db_fetch_object($nodes)) { if($teas) { //$teaser = $node->teaser; $teaser = node_view(node_load($node->nid), true, false, false); } if ($teaser) $output = '
  • '; else $output = '
  • ' . l($node->title, 'node/'. $node->nid, array('title'=>t("view {$node->title} in full") )).'
    '; $output .= $teaser; $output .= '
  • '; $items .= $output; } $content = '
    '; $content .= '
    '; $content .= l(t("more"), 'taxonomy/term/'. implode(array_keys($tids), '+'), array("title" => t("View all."))) .'
    '; $output = '

    '.$description.'

    '.$content; } else $output = ''; return $output; $output = theme('block', $block); return $output; } /** * Implementation of hook_widget_info(). */ function fieldtaxonomy_widget_info() { return array( 'fieldtaxonomy' => array( 'label' => 'Taxonomy block', 'field types' => array('fieldtaxonomy'), ), ); } /** * Implementation of hook_widget(). */ function fieldtaxonomy_widget($op, &$node, $field, &$node_field) { switch ($op) { case 'form': $form = array(); $form[$field['field_name']] = array('#tree' => TRUE); if ($field['multiple']) { // Generate more fields if necessary on preview if ($_POST['edit'][$field['field_name']]) { $node_field = $_POST['edit'][$field['field_name']]; } $delta = 0; // Render two additional new link fields foreach (range($delta, $delta + 1) as $delta) { _fieldtaxonomy_widget_form($form[$field['field_name']][$delta], $field, $node_field, $delta); } } // end if multiple else { _fieldtaxonomy_widget_form($form[$field['field_name']][0], $field, $node_field[0]); } return $form; case 'validate': return; case 'process form values': foreach ($node_field as $delta => $item) { $node_field[$delta]['fieldtaxonomy'] = $node_field[$delta]['taxonomyblock']; } return; case 'prepare form values': foreach($node_field as $delta => $item) { $node_field[$delta]['taxonomyblock'] = $node_field[$delta]['taxonomyblock']; } break; case 'submit': return; } } /** * Helper function renders the link widget in both single and multiple value cases. */ function _fieldtaxonomy_widget_form (&$form_item, $field, $node_field, $delta = 0) { $form_item = array( '#tree' => true, // Add a microweight to keep fields in first-in first-out order '#weight' => $field['widget']['weight'].".00".$delta, ); $vocabs = taxonomy_get_vocabularies(); $links[] = ''; foreach ($vocabs as $vocab) { $links['v'.$vocab->vid] = $vocab->name; $tree = taxonomy_get_tree($vocab->vid); foreach ($tree as $term) { $links[$term->tid] = $vocab->name .' - '. $term->name; } } $form_item['taxonomyblock'] = array( '#type' => 'select', '#title' => $field['title'] == 'none' ? t($field['widget']['label']) : t($field['widget']['label'])." ".t('Taxonomy block'), '#options' => $links, '#default_value' => $node_field['fieldtaxonomy'], '#description' => $field['widget']['description'], ); } /** * Implementation of hook_field_formatter_info(). */ function fieldtaxonomy_field_formatter_info() { return array( 'default' => array( 'label' => 'Default, as link', 'field types' => array('fieldtaxonomy'), ), 'plain' => array( 'label' => 'Plain, no link', 'field types' => array('fieldtaxonomy'), ), ); } /** * Implementation of hook_field_formatter(). * */ function fieldtaxonomy_field_formatter($field, $item, $formatter) { $text = ''; if (isset($item['fieldtaxonomy'])) { } switch ($formatter) { case 'plain': return strip_tags($text); default: return $text; } }