You are here

function bg_image_settings_form in Background Images 6

Same name and namespace in other branches
  1. 7 bg_image.module \bg_image_settings_form()

Defines the settings for for bg_image

1 string reference to 'bg_image_settings_form'
bg_image_menu in ./bg_image.module
Implements hook_menu().

File

./bg_image.module, line 46
Allows for customizable background images per page

Code

function bg_image_settings_form(&$form_state) {

  // Init some variables
  $form = array();

  // '#validate' => array('bg_image_settings_form_validate'));
  $node_types = array(
    '' => 'choose...',
  );
  $node_fields = array(
    '' => 'Choose a node type first...',
  );

  // Options for repeating the image
  $repeat_options = bg_image_css_repeat_options();

  // Make an option list of node types
  foreach (node_get_types('types', NULL, TRUE) as $id => $node_type) {
    $node_types[$id] = $node_type->name;
  }

  // If this is a page rebuild for AJAX callback we need
  // create the field list for the specified node type
  // Only fields of the type 'image' will be accepted
  if (isset($form_state['values']['bg_image_node_type'])) {
    $node_fields = bg_image_get_fields_for_node_type($form_state['values']['bg_image_node_type']);
  }
  elseif (variable_get('bg_image_node_type', '')) {
    $node_fields = bg_image_get_fields_for_node_type(variable_get('bg_image_node_type', ''));
  }

  // The fieldset for node settings
  $form['node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Node Settings'),
    '#description' => t('The background images can be added using nodes as the interface to upload and manage the images. In order to use this feature you need to specify the node type and field name here. Some modules may require this to be done before they will work.'),
  );

  // Select a node type
  $form['node']['bg_image_node_type'] = array(
    '#type' => 'select',
    '#title' => t('Node Type'),
    '#description' => t('The node type that holds the image for use with background image.'),
    '#options' => $node_types,
    '#default_value' => variable_get('bg_image_node_type', ''),
    '#required' => TRUE,
    '#ahah' => array(
      'path' => 'bg-image/js',
      'wrapper' => 'bg-image-node-field',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );

  // The actual field to use as the bg image
  $form['node']['bg_image_node_field'] = array(
    '#type' => 'select',
    '#title' => t('Node field'),
    '#description' => t('The field within the node type specified above to use as the image'),
    '#options' => $node_fields,
    '#default_value' => variable_get('bg_image_node_field', ''),
    '#required' => TRUE,
    '#prefix' => '<div id="bg-image-node-field">',
    '#suffix' => '</div>',
  );

  // The fieldset for exlusions
  $form['exclusions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global Exclusions'),
    '#description' => t('Choose specific pages/sections to exclude the background image from appearing on. This will apply to all background images'),
  );
  $form['exclusions']['bg_image_exclude_admin'] = array(
    '#type' => 'checkbox',
    '#title' => t('Exclude from Admin Pages'),
    '#description' => t('Background Images will be ignored on admin pages.'),
    '#default_value' => variable_get('bg_image_exclude_admin', 0),
  );
  if (module_exists('imagecache')) {

    // Apply an imagecache preset?
    $form['imagecache_preset'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Manipulation'),
      '#description' => t('Manipulate the image before outputting as a background image'),
    );
    $imagecache_presets = array(
      '' => '- None -',
    );
    foreach (imagecache_presets() as $preset) {
      $imagecache_presets[$preset['presetname']] = $preset['presetname'];
    }
    $form['imagecache_preset']['bg_imagecache_preset'] = array(
      '#type' => 'select',
      '#title' => t('Imagecache Preset'),
      '#description' => t('Apply an imagecache preset to the image'),
      '#options' => $imagecache_presets,
      '#default_value' => variable_get('bg_imagecache_preset', ''),
    );
  }

  // Fieldset for css settings
  $form['css_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default CSS Settings'),
    '#description' => t('Default CSS settings for outputting the background property. These settings will be concatenated to form a complete css statement that uses the "background" property. For more information on the css background property see http://www.w3schools.com/css/css_background.asp"'),
  );

  // The selector for the background property
  $form['css_settings']['bg_image_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('Selector'),
    '#description' => t('A valid CSS selector that will be used to apply the background image.'),
    '#default_value' => variable_get('bg_image_selector', ''),
  );

  // The selector for the background property
  $form['css_settings']['bg_image_color'] = array(
    '#type' => 'textfield',
    '#title' => t('Color'),
    '#description' => t('The background color formatted as any valid css color format (e.g. hex, rgb, text, hsl) [<a href="http://www.w3schools.com/css/pr_background-color.asp">css property: background-color</a>]'),
    '#default_value' => variable_get('bg_image_color', '#FFFFFF'),
  );

  // The selector for the background property
  $form['css_settings']['bg_image_x'] = array(
    '#type' => 'textfield',
    '#title' => t('Horizontal Alignment'),
    '#description' => t('The horizontal alignment of the background image formatted as any valid css alignment. [<a href="http://www.w3schools.com/css/pr_background-position.asp">css property: background-position</a>]'),
    '#default_value' => variable_get('bg_image_x', 'left'),
  );

  // The selector for the background property
  $form['css_settings']['bg_image_y'] = array(
    '#type' => 'textfield',
    '#title' => t('Vertical Alignment'),
    '#description' => t('The vertical alignment of the background image formatted as any valid css alignment. [<a href="http://www.w3schools.com/css/pr_background-position.asp">css property: background-position</a>]'),
    '#default_value' => variable_get('bg_image_y', 'top'),
  );

  // The selector for the background property
  $form['css_settings']['bg_image_attachment'] = array(
    '#type' => 'radios',
    '#title' => t('Background Attachment'),
    '#description' => t('The attachment setting for the background image. [<a href="http://www.w3schools.com/css/pr_background-attachment.asp">css property: background-attachment</a>]'),
    '#options' => array(
      'scroll' => 'Scroll',
      'fixed' => 'Fixed',
    ),
    '#default_value' => variable_get('bg_image_attachment', 'scroll'),
  );

  // The background-repeat property
  $form['css_settings']['bg_image_repeat'] = array(
    '#type' => 'radios',
    '#title' => t('Background Repeat'),
    '#description' => t('Define the repeat settings for the background image. [<a href="http://www.w3schools.com/css/pr_background-repeat.asp">css property: background-repeat</a>]'),
    '#options' => $repeat_options,
    '#default_value' => variable_get('bg_image_repeat', 'no-repeat'),
  );

  // The background-size property
  $form['css_settings']['bg_image_background_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Background Size'),
    '#description' => t('The size of the background (NOTE: CSS3 only. Useful for responsive designs) [<a href="http://www.w3schools.com/cssref/css3_pr_background-size.asp">css property: background-size</a>]'),
    '#default_value' => variable_get('bg_image_background_size', ''),
  );

  // background-size:cover suppor for IE8
  $form['css_settings']['bg_image_background_size_ie8'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add background-size:cover support for ie8'),
    '#description' => t('The background-size css property is only supported on browsers that support CSS3. However, there is a workaround for IE using Internet Explorer\'s built-in filters (http://msdn.microsoft.com/en-us/library/ms532969%28v=vs.85%29.aspx). Check this box to add the filters to the css. Sometimes it works well, sometimes it doesn\'t. Use at your own risk'),
    '#default_value' => variable_get('bg_image_background_size_ie8', 0),
  );

  // The media query specifics
  $form['css_settings']['bg_image_media_query'] = array(
    '#type' => 'textfield',
    '#title' => t('Media Query'),
    '#description' => t('Apply this background image css using a media query. CSS3 Only. Useful for responsive designs. example: only screen and (min-width:481px) and (max-width:768px) [<a href="http://www.w3.org/TR/css3-mediaqueries/">Read about media queries</a>]'),
    '#default_value' => variable_get('bg_image_media_query', 'all'),
  );
  $form['css_settings']['bg_image_important'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add "!important" to the background property.'),
    '#description' => t('This can be helpful to override any existing background image or color properties added by the theme.'),
    '#default_value' => variable_get('bg_image_important', 1),
  );
  return system_settings_form($form);
}