function ds_render_content in Display Suite 6
Same name and namespace in other branches
- 6.3 includes/ds.api.inc \ds_render_content()
- 6.2 ds.module \ds_render_content()
Render content for an object.
Parameters
stdClass $object The object to manipulate.:
string $module The module that is requesting.:
array $vars The variables need for rendering.:
string $theme_function The theming function for a field.:
1 call to ds_render_content()
- views_plugin_ds_fields_view::ds_fields_render in views/
views_plugin_ds_fields_view.inc - Render the fields.
File
- ./
ds.module, line 324
Code
function ds_render_content($object, $module, $vars, $theme_function = 'ds_field') {
// API info for this module and type. This doesn't cost a lot
// since it will be cached already in ds_build_fields_and_regions().
$api_info = ds_api_info($module, $object->type);
// Display settings for this module and object.
$display_settings = variable_get($module . '_display_settings_' . $object->type, array());
$region_styles = ds_default_value($display_settings, $object->build_mode, 'region_styles');
$all_regions = ds_regions('all', TRUE);
$regions = $vars['regions'];
$themed_regions = array();
// Create key_rendered fields from DS_FIELD_TYPE_PREPROCESS and DS_FIELD_TYPE_IGNORE.
if (!empty($object->preprocess_fields)) {
foreach ($object->preprocess_fields as $key => $type) {
$vars_key = NULL;
if (is_array($type)) {
$vars_key = $type['key'];
$type = $type['type'];
}
switch ($type) {
case DS_FIELD_TYPE_PREPROCESS:
$field_key = $key . '_rendered';
if (!empty($vars_key)) {
$vars[$field_key] = $vars[$key][$vars_key];
}
else {
$vars[$field_key] = $vars[$key];
}
break;
case DS_FIELD_TYPE_IGNORE:
$field_key = $key . '_rendered';
$vars[$field_key] = $object->content[$key]['#value'];
break;
}
}
}
// Any groups which have nested content?
if (!empty($object->ds_groups)) {
foreach ($object->ds_groups as $group => $fields) {
asort($fields);
$group_content = '';
$field_count = 0;
$group_fields = array();
foreach ($fields as $key => $weight) {
$field_content = isset($vars[$key . '_rendered']) ? $vars[$key . '_rendered'] : '';
if (!empty($field_content)) {
$group_content .= theme($theme_function, $field_content, $object->ds_fields[$key]);
$field_count++;
$group_fields[] = $object->ds_fields[$key];
unset($object->ds_fields[$key]);
}
}
// Store group_content as content key in group key of ds_fields.
if (!empty($group_content)) {
// Support for tabs. We need to create an additional field and unset
// the existing group field.
if ($object->ds_fields[$group]['theme'] == 'ds_tabs') {
unset($regions[$object->ds_fields[$group]['region']][$group]);
$regions[$object->ds_fields[$group]['region']]['tab_' . $object->ds_fields[$group]['region']] = $object->ds_fields[$group]['weight'];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['tab'] = TRUE;
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['name'] = $object->ds_fields[$group]['region'];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['fields'][$object->ds_fields[$group]['weight']] = $object->ds_fields[$group];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['fields'][$object->ds_fields[$group]['weight']]['content'] = $group_content;
unset($object->ds_fields[$group]);
}
else {
$object->ds_fields[$group]['content'] = $group_content;
$object->ds_fields[$group]['count'] = $field_count;
$object->ds_fields[$group]['fields'] = $group_fields;
}
}
else {
unset($object->ds_fields[$group]);
}
}
}
// Loop through all regions.
$region_classes = array();
foreach ($all_regions as $region_name => $region_title) {
if (isset($regions[$region_name])) {
$region_content = '';
$region = $regions[$region_name];
$count = 0;
$region_fields = array();
// Loop through all fields after ordering on weight.
asort($region);
foreach ($region as $key => $weight) {
// Theming function. This implies a 'content' key exists.
if (isset($object->ds_fields[$key]['theme']) && isset($object->ds_fields[$key]['content'])) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme($object->ds_fields[$key]['theme'], $object->ds_fields[$key]['content'], $object->ds_fields[$key]);
}
elseif (isset($object->ds_fields[$key]['tab'])) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme('ds_tabs', $object->ds_fields[$key]);
}
else {
$field_content = isset($vars[$key . '_rendered']) ? $vars[$key . '_rendered'] : '';
if (!empty($field_content)) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme($theme_function, $field_content, $object->ds_fields[$key]);
}
}
}
// Store content from a region and add classes if necessary.
if (!empty($region_content)) {
if ($region_name == 'left' || $region_name == 'right') {
$region_classes[$region_name] = $region_name;
}
$style = isset($region_styles[$region_name]) ? ' ' . $region_styles[$region_name] : '';
$themed_regions[$region_name] = array(
'content' => $region_content,
'extra_class' => $style,
'count' => $count,
'fields' => $region_fields,
);
}
}
}
$object_display = new stdClass();
$object_display->all_regions = $all_regions;
$object_display->themed_regions = $themed_regions;
$object_display->region_classes = $region_classes;
$object_display->build_mode = $object->build_mode;
// Plugins.
ds_plugins_process($module, $api_info['object'], $display_settings, $vars, $object_display);
// Add classes based on regions.
if (isset($object_display->themed_regions['middle'])) {
$middle_class = $module . '-no-sidebars';
if (isset($object_display->region_classes['left']) && isset($object_display->region_classes['right'])) {
$middle_class = $module . '-two-sidebars';
}
elseif (isset($object_display->region_classes['left'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-left';
}
elseif (isset($object_display->region_classes['right'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-right';
}
$object_display->themed_regions['middle']['extra_class'] .= ' ' . $middle_class;
}
// Theme the regions with their content.
return theme('ds_regions', $object_display, $module);
}