function ds_render_block_field in Display Suite 7
Same name and namespace in other branches
- 7.2 ds.module \ds_render_block_field()
Render a block field.
1 call to ds_render_block_field()
- ds_get_field_value in ./
ds.module - Get the value for a Display Suite field.
File
- ./
ds.module, line 1093 - Display Suite core functions.
Code
function ds_render_block_field($field) {
list($module, $delta) = explode('|', $field['properties']['block']);
$block = module_invoke($module, 'block_view', $delta);
if (isset($block['content']) && is_array($block['content'])) {
$block['content'] = drupal_render($block['content']);
}
if (!empty($block['content'])) {
global $theme_key;
$block_title = db_query("SELECT title FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
':module' => $module,
':delta' => $delta,
':theme' => $theme_key,
))
->fetchField();
if (!empty($block_title)) {
$block['subject'] = $block_title == '<none>' ? '' : check_plain($block_title);
}
// i18n support.
if (function_exists('i18n_block_block_view_alter')) {
// Check language visibility.
global $language;
static $block_languages = FALSE;
if (!$block_languages) {
$block_languages = array();
$result = db_query('SELECT module, delta, language FROM {i18n_block_language}');
foreach ($result as $record) {
$block_languages[$record->module][$record->delta][$record->language] = TRUE;
}
}
if (isset($block_languages[$module][$delta]) && !isset($block_languages[$module][$delta][$language->language])) {
return;
}
// Translate.
$i18n_block = db_query("SELECT * FROM {block} WHERE module = :module AND delta = :delta", array(
':module' => $module,
':delta' => $delta,
))
->fetchObject();
if (!empty($i18n_block->i18n_mode)) {
i18n_block_block_view_alter($block, $i18n_block);
// OH WTF ...
if (!empty($i18n_block->title)) {
$block['subject'] = $i18n_block->title;
}
}
}
$block = (object) $block;
switch ($field['properties']['block_render']) {
case DS_BLOCK_TEMPLATE:
if (!isset($block->subject)) {
$block->subject = NULL;
}
$block->region = NULL;
$block->module = $module;
$block->delta = $delta;
$elements = array(
'elements' => array(
'#block' => $block,
'#children' => $block->content,
),
);
// Add contextual links
if (module_exists('contextual') && user_access('access contextual links')) {
$elements['elements'] += array(
'#contextual_links' => array(
'block' => array(
'admin/structure/block/manage',
array(
$block->module,
$block->delta,
),
),
),
);
}
return theme('block', $elements);
break;
case DS_BLOCK_TITLE_CONTENT:
return '<h2 class="block-title">' . $block->subject . '</h2>' . $block->content;
break;
case DS_BLOCK_CONTENT:
return $block->content;
break;
}
}
}