You are here

function dynamic_background_preprocess_html in Dynamic Background 7.2

Same name and namespace in other branches
  1. 7 dynamic_background.module \dynamic_background_preprocess_html()

Implements hook_preprocess_html().

Used to create the $background variable, so it can be used in html.tpl.php. If selected have selected to use custom CSS, the image will automatically be added to the page header.

File

./dynamic_background.module, line 401
This module enables administrators to upload images used as background on the site. The selected background image link is exposed as either $background in the page.tpl file or as /background.css.

Code

function dynamic_background_preprocess_html(&$vars) {

  // Load image configuration.
  $image_conf = dynamic_background_load_image_configuration($vars);

  // Generate the css and add it to the site.
  if (isset($image_conf)) {
    $css = dynamic_background_create_css($image_conf);
    if ($css) {
      drupal_add_css($css, array(
        'type' => 'inline',
        'group' => 200,
      ));
    }

    // Set the one with the highest weight as the variable.
    if (!empty($image_conf)) {
      $image = array_pop($image_conf);
      $vars['background'] = 'style="background-image: url(\'' . file_create_url($image['image']->uri) . '\')"';
    }
  }
}