class context_respect_reaction_block in Context Respect 7
Same name and namespace in other branches
- 6 plugins/context_respect_reaction_block.inc \context_respect_reaction_block
Expose permissions as context reactions.
Hierarchy
- class \context_reaction
- class \context_reaction_block
Expanded class hierarchy of context_respect_reaction_block
2 string references to 'context_respect_reaction_block'
- context_respect_context_plugins in ./
context_respect.module - Implements hook_context_plugins().
- context_respect_context_registry_alter in ./
context_respect.module - Implements hook_context_registry_alter().
File
- plugins/
context_respect_reaction_block.inc, line 12 - Context Respect reaction plugin file.
View source
class context_respect_reaction_block extends context_reaction_block {
/**
* Override of block_list().
* An alternative version of block_list() that provides any context enabled blocks.
*/
function block_list($region) {
module_load_include('module', 'block', 'block');
$context_blocks =& drupal_static('context_reaction_block_list');
$contexts = context_active_contexts();
if (!isset($context_blocks)) {
$info = $this
->get_blocks();
$context_blocks = array();
foreach ($contexts as $context) {
$options = $this
->fetch_from_context($context);
if (!empty($options['blocks'])) {
foreach ($options['blocks'] as $block) {
$bid = $block['module'] . '-' . $block['delta'];
if (!isset($info[$bid])) {
continue;
}
// Copy general block settings.
$block = (object) array_merge((array) $info[$bid], $block);
// Set context name and others.
$block->context = $context->name;
$block->title = isset($info[$block->bid]->title) ? $info[$block->bid]->title : NULL;
$block->cache = isset($info[$block->bid]->cache) ? $info[$block->bid]->cache : DRUPAL_NO_CACHE;
// Check role access
$role_match = $this
->check_role_match($block);
// Check path access
$page_match = $this
->check_page_match($block);
if ($page_match && $role_match) {
$context_blocks[$block->region][$block->bid] = $block;
}
}
}
}
$this
->is_editable_check($context_blocks);
foreach ($context_blocks as $r => $blocks) {
$context_blocks[$r] = _block_render_blocks($blocks);
// Make blocks editable if allowed.
if ($this
->is_editable_region($r)) {
foreach ($context_blocks[$r] as $key => $block) {
$context_blocks[$r][$key] = $this
->editable_block($block);
}
}
// Sort blocks.
uasort($context_blocks[$r], array(
'context_reaction_block',
'block_sort',
));
}
}
return isset($context_blocks[$region]) ? $context_blocks[$region] : array();
}
/**
* Helper function for determining if authenticated user has access
* to a block.
*
* @param $block
* A block object.
*
* @return $role_match
* Boolean determining if logged in user has block access
*/
protected function check_role_match($block) {
global $user;
$role_match = FALSE;
// Check for overriden variables
$overrides = variable_get('context_respect_override_role', false);
if ($overrides) {
foreach ($overrides as $or_bid => $or_val) {
if ($or_bid == $block->bid) {
return $or_val;
}
}
}
$rids = array_keys($user->roles);
$result = db_query("SELECT rid FROM {block_role} b WHERE b.delta = :delta and b.module = :module", array(
':delta' => $block->delta,
':module' => $block->module,
));
// if the block has no roles, return TRUE until they choose to use visibility settings
if (!$result
->rowCount()) {
return TRUE;
}
foreach ($result as $b) {
if (in_array($b->rid, $rids)) {
$role_match = TRUE;
}
}
return $role_match;
}
/**
* Helper function for determining if page level access is granted to current
* block.
*
* @param $block
* A block object.
*
* @return $page_match
* Boolean determining if page access is granted to block
*/
protected function check_page_match($block) {
// Check for overriden variables
$overrides = variable_get('context_respect_override_page', false);
if ($overrides) {
foreach ($overrides as $or_bid => $or_val) {
if ($or_bid == $block->bid) {
return $or_val;
}
}
}
$block_data = db_query("SELECT pages, visibility FROM {block} b where b.delta = :delta and b.module = :module", array(
':delta' => $block->delta,
':module' => $block->module,
))
->fetch();
$page_match = TRUE;
// Bypass check if there are no pages set for a block
if (!empty($block_data) && !$block_data->pages || drupal_match_path($_GET['q'], 'admin/structure/context*') || !$block_data) {
return TRUE;
}
if (!empty($block_data) && $block_data->visibility < 2) {
$path = drupal_get_path_alias($_GET['q']);
$page_match = drupal_match_path($path, $block_data->pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $block_data->pages);
}
// When $block_data->visibility has a value of 0, the block is displayed on
// all pages except those listed in $block_data->pages. When set to 1, it
// is displayed only on those pages listed in $block_data->pages.
$page_match = !($block_data->visibility xor $page_match);
}
elseif (!empty($block_data) && module_exists('php')) {
$page_match = php_eval($block_data->pages);
}
return $page_match;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
function | Retrieve options from the context provided. | 1 | |
context_reaction:: |
function | Retrieve active contexts that have values for this reaction. | ||
context_reaction:: |
function | Clone our references when we're being cloned. | ||
context_reaction:: |
function | Constructor. Do not override. | ||
context_reaction_block:: |
function | Get a renderable array of a region containing all enabled blocks. | ||
context_reaction_block:: |
static | function | Sort callback. | |
context_reaction_block:: |
private | function | Allow modules to selectively allow ajax rendering of a specific block | |
context_reaction_block:: |
protected | function | Add markup for making a block editable. | |
context_reaction_block:: |
protected | function | Add markup for making a region editable. | |
context_reaction_block:: |
function | Context editor form for blocks. | 1 | |
context_reaction_block:: |
function | Submit handler context editor form. | 1 | |
context_reaction_block:: |
function | Execute. | ||
context_reaction_block:: |
function | Helper function to generate a list of blocks from a specified region. If provided a context object, will generate a full list of blocks for that region distinguishing between system blocks and context-provided blocks. | ||
context_reaction_block:: |
function | Determine if there is an active context editor block, and set a flag. We will set a flag so that we can make sure that blocks with empty content have some default content. This is needed so the save of the context inline editor does not remove the… | ||
context_reaction_block:: |
protected | function | Determine whether inline editing requirements are met and that the current user may edit. | |
context_reaction_block:: |
protected | function | Return a list of enabled regions for which blocks should be built. Split out into a separate method for easy overrides in extending classes. | 1 |
context_reaction_block:: |
protected | function | Compatibility wrapper around json_decode(). | |
context_reaction_block:: |
protected | function | Generate the safe weight range for a block being added to a region such that there are enough potential unique weights to support all blocks. | |
context_reaction_block:: |
function |
Options form. Overrides context_reaction:: |
1 | |
context_reaction_block:: |
function |
Options form submit handler. Overrides context_reaction:: |
1 | |
context_reaction_block:: |
function | Check or set whether a rebuild of the block info cache is needed. | ||
context_reaction_block:: |
function | Block renderer for AJAX requests. Triggered when $_GET['context_block'] is set. See ->execute() for how this is called. | ||
context_reaction_block:: |
function |
Settings form for variables. Overrides context_reaction:: |
||
context_reaction_block:: |
protected | function | Provide caching for system_region_list since it can get called frequently. Evaluate for removal once https://drupal.org/node/1873450 lands or system_region_list is otherwise cached in core | |
context_respect_reaction_block:: |
function |
Override of block_list().
An alternative version of block_list() that provides any context enabled blocks. Overrides context_reaction_block:: |
||
context_respect_reaction_block:: |
protected | function | Helper function for determining if page level access is granted to current block. | |
context_respect_reaction_block:: |
protected | function | Helper function for determining if authenticated user has access to a block. |