class Context_Block_Disable_Reaction in Context Block Disable 7.2
Same name and namespace in other branches
- 7 plugins/context_block_disable_reaction.inc \Context_Block_Disable_Reaction
Context reaction plugin for disabling blocks.
Hierarchy
- class \context_reaction
- class \context_reaction_block
Expanded class hierarchy of Context_Block_Disable_Reaction
1 string reference to 'Context_Block_Disable_Reaction'
File
- plugins/
context_block_disable_reaction.inc, line 13 - Context reaction plugin for disabling blocks.
View source
class Context_Block_Disable_Reaction extends context_reaction_block {
// The block this plugin needs to consider.
protected $reaction_block = NULL;
/**
* Implements options_form() callback.
*
* Overrides the parent function in order to pull out only the part of the
* form we care about, and adjust the selected values due to that change.
*/
public function options_form($context) {
// Rebuild the block info cache if necessary.
$this
->get_blocks(NULL, NULL, $this
->rebuild_needed());
$this
->rebuild_needed(FALSE);
$settings = $this
->fetch_from_context($context);
$form = array(
'#tree' => TRUE,
);
$modules = module_list();
$form['selector'] = array(
'#type' => 'item',
'#tree' => TRUE,
);
foreach ($this
->get_blocks() as $block) {
$group = isset($block->context_group) ? $block->context_group : $block->module;
if (!isset($form['selector'][$group])) {
$form['selector'][$group] = array(
'#type' => 'checkboxes',
'#title' => isset($block->context_group) ? $block->context_group : $modules[$block->module],
'#options' => array(),
);
}
$form['selector'][$group]['#options'][$block->bid] = check_plain($block->info);
// Set up the selected blocks.
if (!empty($settings['blocks'][$block->bid])) {
$form['selector'][$group]['#default_value'][] = $block->bid;
}
}
ksort($form['selector']);
return $form;
}
/**
* Implements options_form_submit() callback.
*
* Overrides the parent function in order to handle the lack of regions in
* this plugin.
*/
public function options_form_submit($values) {
$blocks = array();
$block_info = $this
->get_blocks();
foreach ($values['selector'] as $module => $selections) {
foreach ($selections as $selected) {
if (!empty($selected)) {
$blocks[$selected] = array(
'module' => $block_info[$selected]->module,
'delta' => $block_info[$selected]->delta,
'region' => $block_info[$selected]->region,
'weight' => $block_info[$selected]->weight,
);
}
}
}
return array(
'blocks' => $blocks,
);
}
/**
* Disables selected modules if a condition implements this plugin.
*
* @param array &$data
* The block data array (subject, content).
*
* @see hook_block_view_alter()
*/
public function execute(&$data) {
// Exit early if no reaction block was set or data has no content.
if (empty($this->reaction_block) || empty($data['content'])) {
return;
}
$block = $this->reaction_block;
// Construct a bid that matches what we use on the settings form and what
// context_reaction_block also uses.
$bid = $block->module . '-' . $block->delta;
$contexts = $this
->get_contexts();
foreach ($contexts as $context) {
if (!empty($context->reactions[$this->plugin])) {
$blocks = $context->reactions[$this->plugin]['blocks'];
if (!empty($blocks[$bid])) {
// Swap non-render arrays into render arrays when configured as such.
if (variable_get('context_block_disable_force_array', FALSE)) {
if (!is_array($data['content'])) {
$data['content'] = array(
'#markup' => $data['content'],
);
}
}
if (is_array($data['content'])) {
// Leave the actual block contents alone, just stop users from being
// able to access it.
$data['content']['#access'] = FALSE;
}
else {
$data['content'] = NULL;
}
}
}
}
}
/**
* Sets the block this plugin should use for comparison operations.
*
* @param object $block
* A block object that at minimum contains the module and delta properties.
*/
public function set_reaction_block($block) {
$this->reaction_block = $block;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Context_Block_Disable_Reaction:: |
protected | property | ||
Context_Block_Disable_Reaction:: |
public | function |
Disables selected modules if a condition implements this plugin. Overrides context_reaction_block:: |
|
Context_Block_Disable_Reaction:: |
public | function |
Implements options_form() callback. Overrides context_reaction_block:: |
|
Context_Block_Disable_Reaction:: |
public | function |
Implements options_form_submit() callback. Overrides context_reaction_block:: |
|
Context_Block_Disable_Reaction:: |
public | function | Sets the block this plugin should use for comparison operations. | |
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:: |
function | An alternative version of block_list() that provides any context 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 | 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 | 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 |