You are here

public function Context_Block_Disable_Reaction::execute in Context Block Disable 7

Same name and namespace in other branches
  1. 7.2 plugins/context_block_disable_reaction.inc \Context_Block_Disable_Reaction::execute()

Disables selected modules if a condition implements this plugin.

Parameters

array &$data: The block data array (subject, content).

Overrides context_reaction_block::execute

See also

hook_block_view_alter()

File

plugins/context_block_disable_reaction.inc, line 99
Context reaction plugin for disabling blocks.

Class

Context_Block_Disable_Reaction
Context reaction plugin for disabling blocks.

Code

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;
        }
      }
    }
  }
}