You are here

function bg_image_context_reaction_bg_image::execute in Background Images 6

Same name and namespace in other branches
  1. 7 bg_image_context/plugins/bg_image_context_reaction_bg_image.inc \bg_image_context_reaction_bg_image::execute()

Organizes the background image data into an array keyed by the selector, then applies the background image with the highest weight for each selector

File

plugins/bg_image_context_reaction_bg_image.inc, line 150

Class

bg_image_context_reaction_bg_image
Expose themes as context reactions.

Code

function execute() {
  $bg_image_nodes = array();
  $contexts = context_active_contexts();
  foreach ($contexts as $context) {
    if (!empty($context->reactions[$this->plugin])) {
      $weight = $context->reactions[$this->plugin]['bg_image_weight'];
      $selector = $context->reactions[$this->plugin]['css_settings']['bg_image_selector'];
      $bg_imagecache_preset = $context->reactions[$this->plugin]['bg_imagecache_preset'];

      // If the css settings are selected to be overridden we use them
      if ($context->reactions[$this->plugin]['override_css_settings']) {
        $css_settings = $context->reactions[$this->plugin]['css_settings'];
      }
      else {
        $css_settings = array();
      }
      $bg_image_nodes[$selector][$weight] = array(
        'nid' => $context->reactions[$this->plugin]['bg_image_node_ref_nid'],
        'css_settings' => $css_settings,
        'bg_imagecache_preset' => $bg_imagecache_preset,
      );
    }
  }
  if ($bg_image_nodes) {
    foreach ($bg_image_nodes as $selector => $values) {
      ksort($values);
      $bg_image_node = end($values);
      bg_image_add_background_image_from_node($bg_image_node['nid'], $bg_image_node['css_settings'], $bg_image_node['bg_imagecache_preset']);
    }
  }
}