function ds_render_ctools_field in Display Suite 7
Same name and namespace in other branches
- 7.2 ds.module \ds_render_ctools_field()
Render a CTools field.
1 call to ds_render_ctools_field()
- ds_get_field_value in ./
ds.module - Get the value for a Display Suite field.
File
- ./
ds.module, line 1019 - Display Suite core functions.
Code
function ds_render_ctools_field($field) {
if (isset($field['formatter_settings']['ctools'])) {
// Extreme use case where a taxonomy_term object is not
// loaded on the entity and triggers notices if a view is embedded
// with taxonomy term fields from the same object.
// see http://drupal.org/node/1238132 - To reproduce:
// 1) add 2 taxonomy field instances on a bundle
// 2) configure a ds layout showing only one
// 3) embed a view with the 2 taxonomies as fields.
if (isset($field['formatter_settings']['load_terms']) && $field['formatter_settings']['load_terms']) {
static $terms_loaded = array();
$language = $field['entity']->language;
$instances = field_info_instances($field['entity_type'], $field['bundle']);
foreach ($instances as $key => $instance) {
$info = field_info_field($key);
if ($info['module'] == 'taxonomy') {
if (empty($field['entity']->{$key})) {
continue;
}
if (!isset($field['entity']->{$key}[$language])) {
$language = LANGUAGE_NONE;
}
foreach ($field['entity']->{$key}[$language] as $tkey => $item) {
if (isset($item['tid']) && !isset($item['taxonomy_term'])) {
if (!isset($terms_loaded[$item['tid']])) {
$terms_loaded[$item['tid']] = taxonomy_term_load($item['tid']);
}
$field['entity']->{$key}[$language][$tkey]['taxonomy_term'] = $terms_loaded[$item['tid']];
}
}
}
}
}
ctools_include('content');
ctools_include('context');
// Get variables.
$show_title = $field['formatter_settings']['show_title'];
$title_wrapper = trim($field['formatter_settings']['title_wrapper']);
$ctools = unserialize($field['formatter_settings']['ctools']);
$type = $ctools['type'];
$subtype = $ctools['subtype'];
$conf = $ctools['conf'];
$entity_type = $field['entity_type'];
$keywords = $arguments = $contexts = array();
// Create entity context.
ds_create_entity_context($entity_type, $field['entity'], $contexts);
// Build the content.
$data = ctools_content_render($type, $subtype, $conf, $keywords, $arguments, $contexts);
// Return content.
if (!empty($data->content)) {
$content = '';
if ($show_title) {
if (empty($title_wrapper)) {
$title_wrapper = 'div';
}
$content .= '<' . check_plain($title_wrapper) . '>' . $data->title . '</' . check_plain($title_wrapper) . '>';
}
if (is_array($data->content)) {
$content .= drupal_render($data->content);
}
else {
$content .= $data->content;
}
return $content;
}
}
}