ds.module | 46 ++++++++++++++++++++++++++++++++++++ modules/ds_ui/includes/ds.fields.inc | 7 ++++++ 2 files changed, 53 insertions(+) diff --git a/ds.module b/ds.module index 8116a0a..c54c7b8 100644 --- a/ds.module +++ b/ds.module @@ -879,6 +879,52 @@ function ds_render_block_field($field) { list($module, $delta) = explode('|', $field['properties']['block']); $block = module_invoke($module, 'block_view', $delta); + if (!empty($field['properties']['block_visibility'])) { + // Check role access. + global $user; + $role_access = TRUE; + // Do the check for all users other than admin. + if ($user->uid != 1) { + $query = db_query("SELECT rid FROM {block_role} b WHERE b.delta = :delta and b.module = :module", array(':delta' => $delta, ':module' => $module)); + // Block roles must be configured to change visibility rules. + if ($query->rowCount() > 0) { + $role_access = FALSE; + $rids = array_keys($user->roles); + $roles = $query->fetchAll(); + foreach ($roles as $r) { + if (in_array($r->rid, $rids)) { + $role_access = TRUE; + } + } + } + } + if (!$role_access) { + return; + } + + // Check page access. + $page_access = TRUE; + $query = db_query("SELECT pages, visibility FROM {block} b where b.delta = :delta and b.module = :module", array(':delta' => $delta, ':module' => $module)); + $data = $query->fetch(); + if ($data->visibility < 2) { + $path = drupal_get_path_alias($_GET['q']); + $page_access = drupal_match_path($path, $data->pages); + if ($path != $_GET['q']) { + $page_access = $page_access || drupal_match_path($_GET['q'], $data->pages); + } + // When $data->visibility has a value of 0, the block is displayed on + // all pages except those listed in $data->pages. When set to 1, it + // is displayed only on those pages listed in $data->pages. + $page_access = !($data->visibility xor $page_access); + } + elseif (module_exists('php')) { + $page_access = php_eval($data->pages); + } + if (!$page_access) { + return; + } + } + // Get contextual links. $contextual_links = array(); $contextual = module_exists('contextual') && user_access('access contextual links'); 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']; } /**