diff --git a/ds.module b/ds.module index 8116a0a..b4c491b 100644 --- a/ds.module +++ b/ds.module @@ -875,91 +875,49 @@ function ds_render_ctools_field($field) { * Render a block field. */ function ds_render_block_field($field) { - // Invoke the block_view hook of the module. + global $theme_key; list($module, $delta) = explode('|', $field['properties']['block']); - $block = module_invoke($module, 'block_view', $delta); - - // Get contextual links. - $contextual_links = array(); - $contextual = module_exists('contextual') && user_access('access contextual links'); - if ($contextual) { - if (isset($block['content']) && is_array($block['content']) && isset($block['content']['#contextual_links'])) { - $contextual_links = $block['content']['#contextual_links']; - } + + // Load the block + $result = db_select('block', 'b') + ->fields('b')->condition('b.theme', $theme_key)->condition('b.module', $module)->condition('b.delta', $delta)->addTag('block_load')->addTag('translatable')->execute(); + $block_info = $result->fetchAllAssoc('bid'); + + // Enable the block + if ($block_info[key($block_info)]->status == 0) { + $block_info[key($block_info)]->status = 1; } - // Render the block content. - if (isset($block['content']) && is_array($block['content'])) { - $block['content'] = drupal_render($block['content']); + // Process the block if it respects visibility settings + if (isset($field['properties']['block_visibility']) && $field['properties']['block_visibility']) { + drupal_alter('block_list', $block_info); } - // Go through in case we have actual content. - if (!empty($block['content'])) { + // Simulate _block_load_blocks() return, containing only our block. + $block = array_shift($block_info); - // Make sure subject is set. - if (!isset($block['subject'])) { - $block['subject'] = ''; - } - - global $theme_key; + // Render the block field + if (isset($block)) { + $key = $module . '_' . $delta; if (module_exists('block')) { - $full_block = db_query("SELECT * FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(':module' => $module, ':delta' => $delta, ':theme' => $theme_key))->fetchObject(); - } - if (!empty($full_block)) { - if ($full_block->title == '') { - $block['subject'] = ''; - } - elseif (!empty($full_block->title)) { - $block['subject'] = $full_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. - if (!empty($full_block->i18n_mode)) { - i18n_block_block_view_alter($block, $full_block); - if (!empty($block['title'])) { - $block['subject'] = $block['title']; - } + $region_blocks = _block_render_blocks(array($key => $block)); + switch ($field['properties']['block_render']) { + case DS_BLOCK_TEMPLATE: + $renderable_block = _block_get_renderable_array($region_blocks); + return drupal_render($renderable_block); + break; + case DS_BLOCK_TITLE_CONTENT: + if (isset($block->subject) && isset($block->content['#markup'])) { + return '

' . $block->subject . '

' . $block->content['#markup']; + } + break; + case DS_BLOCK_CONTENT: + if (isset($block->content['#markup'])) { + return $block->content['#markup']; + } + break; } } - - $block = (object) $block; - switch ($field['properties']['block_render']) { - case DS_BLOCK_TEMPLATE: - $block->region = NULL; - $block->module = $module; - $block->delta = $delta; - $elements = array('elements' => array('#block' => $block, '#children' => $block->content)); - // Add contextual links. - if ($contextual) { - $elements['elements'] += array('#contextual_links' => array_merge($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 '

' . $block->subject . '

' . $block->content; - break; - case DS_BLOCK_CONTENT: - return $block->content; - break; - } } } diff --git a/modules/ds_ui/includes/ds.fields.inc b/modules/ds_ui/includes/ds.fields.inc index babe468..63f7a86 100644 --- a/modules/ds_ui/includes/ds.fields.inc +++ b/modules/ds_ui/includes/ds.fields.inc @@ -377,6 +377,12 @@ function ds_edit_block_field_form($form, &$form_state, $custom_block = '') { '#required' => TRUE, '#default_value' => isset($custom_block->properties['block']) ? $custom_block->properties['block'] : '', ); + $form['block_identity']['block_visibility'] = array( + '#type' => 'checkbox', + '#title' => t('Respect Block Visibility'), + '#description' => t('Toggle this checkbox if you would like this field to respect the same visibility settings configured for the block.'), + '#default_value' => isset($custom_block->properties['block_visibility']) ? $custom_block->properties['block_visibility'] : FALSE, + ); $form['block_identity']['block_render'] = array( '#type' => 'select', '#options' => array( @@ -402,6 +408,7 @@ function ds_block_field_form_validate($form, &$form_state) { $form_state['field']->properties = array(); $form_state['field']->properties['block'] = $form_state['values']['block']; $form_state['field']->properties['block_render'] = $form_state['values']['block_render']; + $form_state['field']->properties['block_visibility'] = $form_state['values']['block_visibility']; } /**