function ctools_context_terms_convert

Convert a context into a string.

1 string reference to 'ctools_context_terms_convert'
terms.inc in plugins/contexts/terms.inc
Plugin to provide a terms context.

File

plugins/contexts/terms.inc, line 64

Code

function ctools_context_terms_convert($context, $type) {
    switch ($type) {
        case 'tid':
            return $context->data->tid;
        case 'tids':
            return $context->argument;
        case 'name':
            return $context->data->name;
        case 'name_dashed':
            return drupal_strtolower(str_replace(' ', '-', $context->data->name));
        case 'names':
        case 'names_dashed':
            // We only run this query if this item was requested:
            if (!isset($context->names)) {
                if (empty($context->tids)) {
                    $context->names = '';
                }
                else {
                    $result = db_query('SELECT tid, name FROM {taxonomy_term_data} WHERE tid IN (:tids)', array(
                        ':tids' => $context->tids,
                    ));
                    foreach ($result as $term) {
                        $names[$term->tid] = $term->name;
                        if ($type == 'names_dashed') {
                            $names[$term->tid] = drupal_strtolower(str_replace(' ', '-', $names[$term->tid]));
                        }
                    }
                    $context->names = implode($context->operator == 'or' ? ' + ' : ', ', $names);
                }
            }
            return $context->names;
        case 'vid':
            return $context->data->vid;
    }
}