You are here

function theme_backgroundfield_formatter_default in BackgroundField 6

File

./backgroundfield.module, line 186

Code

function theme_backgroundfield_formatter_default($element = NULL) {
  global $base_url;
  static $previous_selectors = array();
  $fields = content_fields();
  $cssInfo = $fields[$element['#field_name']];
  if (in_array($cssInfo['css_selector'], $previous_selectors)) {
    return;
  }
  if (!empty($element['#item']['filepath'])) {
    $css = $cssInfo['css_selector'] . ' {
      background-image: url("' . $base_url . '/' . $element['#item']['filepath'] . '");
      background-repeat: ' . $cssInfo['repeat'] . ';
      background-position: ' . $cssInfo['h_position'] . ' ' . $cssInfo['v_position'] . ';
      background-attachment: ' . $cssInfo['attachment'] . ';
      }';
    drupal_set_html_head('<style type="text/css" rel="stylesheet" media="all">' . $css . '</style>');
    $previous_selectors[] = $cssInfo['css_selector'];
  }

  // if has image file
}