You are here

function bg_image_context_reaction_bg_image::options_form 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::options_form()

Allow admins to provide a section title, section subtitle and section class.

File

plugins/bg_image_context_reaction_bg_image.inc, line 11

Class

bg_image_context_reaction_bg_image
Expose themes as context reactions.

Code

function options_form($context) {
  $values = $this
    ->fetch_from_context($context);
  $form = array(
    '#tree' => TRUE,
    '#title' => t('Background Image'),
  );
  if (variable_get('bg_image_node_type', '') && variable_get('bg_image_node_field', '')) {
    $node_type = variable_get('bg_image_node_type', '');
    $node_options = bg_image_node_options();
    $repeat_options = bg_image_css_repeat_options();
    $form['bg_image_node_ref_nid'] = array(
      '#type' => 'select',
      '#title' => t('Select A Node'),
      '#description' => t('Choose a node, whose image field specified on the <a href="/admin/config/content/background_image">settings page</a> will be used for the background image'),
      '#options' => $node_options,
      '#default_value' => isset($values['bg_image_node_ref_nid']) ? $values['bg_image_node_ref_nid'] : 0,
    );
    $form['bg_image_weight'] = array(
      '#type' => 'textfield',
      '#title' => t('weight'),
      '#description' => t('If you want you can set a weight for this background image. This helps if you have overlapping conditions in different contexts trying to add multiple background images. Higher values take precedence.'),
      '#default_value' => isset($values['bg_image_weight']) ? $values['bg_image_weight'] : 0,
    );
    if (module_exists('imagecache')) {
      $imagecache_presets = array(
        '' => '- None -',
      );
      foreach (imagecache_presets() as $preset) {
        $imagecache_presets[$preset['presetname']] = $preset['presetname'];
      }
      $form['bg_imagecache_preset'] = array(
        '#type' => 'select',
        '#title' => t('Imagecache Preset'),
        '#description' => t('Apply an imagecache style to the image'),
        '#options' => $imagecache_presets,
        '#default_value' => isset($values['bg_imagecache_preset']) ? $values['bg_imagecache_preset'] : variable_get('bg_imagecache_preset', ''),
      );
    }
    $form['override_css_settings'] = array(
      '#type' => 'checkbox',
      '#title' => t('Override the default css settings'),
      '#description' => t('If selected the css settings provided below will be used instead of the default css settings from the <a href="/admin/config/content/background-image">background image configuration page</a>'),
      '#default_value' => isset($values['override_css_settings']) ? $values['override_css_settings'] : 0,
    );

    // Default CSS Settings can be overridden here
    // Fieldset for css settings
    $form['css_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Override Default CSS Settings'),
      '#description' => t('Override the default css settings from the <a href="admin/config/admin/config/content/background-image">Background Image Settings Page</a>'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // 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' => isset($values['bg_image_selector']) ? $values['bg_image_selector'] : 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' => isset($values['bg_image_color']) ? $values['bg_image_color'] : 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' => isset($values['bg_image_x']) ? $values['bg_image_x'] : 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' => isset($values['bg_image_y']) ? $values['bg_image_y'] : 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' => isset($values['bg_image_attachment']) ? $values['bg_image_attachment'] : 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' => isset($values['bg_image_repeat']) ? $values['bg_image_repeat'] : 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' => isset($values['bg_image_background_size']) ? $values['bg_image_background_size'] : 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' => isset($values['bg_image_background_size_ie8']) ? $values['bg_image_background_size_ie8'] : 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' => isset($values['bg_image_media_query']) ? $values['bg_image_media_query'] : 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' => isset($values['bg_image_important']) ? $values['bg_image_important'] : variable_get('bg_image_important', 1),
    );
  }
  else {
    $form['settings_first_msg'] = array(
      '#markup' => 'You must specify a content type and field on the <a href="/admin/config/content/background_image">settings page</a> before you can set a background image. Once configured you will be able to reference a specific node here, whose image field will be used to set the background image.',
    );
  }
  return $form;
}