function ctools_node_terms_content_type_render

Render the node_terms content type.

File

plugins/content_types/node_context/node_terms.inc, line 27

Code

function ctools_node_terms_content_type_render($subtype, $conf, $panel_args, $context) {
    if (empty($context) || empty($context->data)) {
        return;
    }
    // Get a shortcut to the node.
    $node = $context->data;
    // Load all terms for this node from all vocabularies.
    $query = db_select('taxonomy_index', 't');
    $result = $query->fields('t')
        ->condition('t.nid', $node->nid)
        ->execute();
    $tids = array();
    foreach ($result as $term) {
        $tids[] = $term->tid;
    }
    // Get the real term objects.
    $term_objects = taxonomy_term_load_multiple($tids);
    $terms = array();
    if (empty($conf['vid'])) {
        // All terms.
        foreach ($term_objects as $term) {
            $terms['taxonomy_term_' . $term->tid] = array(
                'title' => check_plain($term->name),
                'href' => 'taxonomy/term/' . $term->tid,
                'attributes' => array(
                    'rel' => 'tag',
                    'title' => strip_tags($term->description),
                ),
            );
        }
    }
    else {
        // They want something special and custom, we'll have to do this ourselves.
        foreach ($term_objects as $term) {
            if ($term->vid == $conf['vid']) {
                if ($conf['term_format'] == 'term-links') {
                    $terms['taxonomy_term_' . $term->tid] = array(
                        'title' => $term->name,
                        'href' => 'taxonomy/term/' . $term->tid,
                        'attributes' => array(
                            'rel' => 'tag',
                            'title' => strip_tags($term->description),
                        ),
                    );
                }
                elseif (empty($conf['link'])) {
                    $terms[] = check_plain($term->name);
                }
                else {
                    $terms[] = l($term->name, 'taxonomy/term/' . $term->tid, array(
                        'attributes' => array(
                            'rel' => 'tag',
                            'title' => strip_tags($term->description),
                        ),
                    ));
                }
            }
        }
    }
    $formatted_terms = '';
    switch ($conf['term_format']) {
        case 'term-links':
            drupal_alter('link', $terms, $node);
            $formatted_terms = theme('links', array(
                'links' => $terms,
            ));
            break;
        case 'ul':
            $formatted_terms = theme('item_list', array(
                'items' => $terms,
            ));
            break;
        case 'inline-delimited':
            $delimiter = isset($conf['term_delimiter']) ? $conf['term_delimiter'] : ', ';
            $processed_terms = array();
            foreach ($terms as $key => $term) {
                if (is_string($term)) {
                    $processed_terms[$key] = $term;
                }
                else {
                    $terms[$key] = l($term['title'], $term['href'], $term);
                }
            }
            $formatted_terms = implode($delimiter, $processed_terms);
            break;
    }
    // Build the content type block.
    $block = new stdClass();
    $block->module = 'node_terms';
    $block->delta = $node->nid;
    $block->title = t('Terms');
    $block->content = $formatted_terms;
    return $block;
}