You are here

function dynamic_background_image_selector_form in Dynamic Background 7.2

Same name and namespace in other branches
  1. 6 dynamic_background.module \dynamic_background_image_selector_form()
  2. 7 dynamic_background.module \dynamic_background_image_selector_form()

Builds image selection part of a form to be used by sub-moduels, where the user may select background images.

Parameters

int $active_image:

Return value

array $form

6 calls to dynamic_background_image_selector_form()
DynamicBackgroundReaction::options_form in modules/dynamic_background_context/plugins/dynamic_background_context_reaction.inc
dynamic_background_blog_form in modules/dynamic_background_blog/dynamic_background_blog.module
Menu callback that generates the form used in the "My blog background" tab on the user profile page.
dynamic_background_node_form_alter in modules/dynamic_background_node/dynamic_background_node.module
Implements hook_form_alter().
dynamic_background_panels_form_alter in modules/dynamic_background_panels/dynamic_background_panels.module
Implements hook_form_alter().
dynamic_background_user_form in modules/dynamic_background_user/dynamic_background_user.module
Menu callback that generates the form used in the "My background" tab on the profile page.

... See full list

File

./dynamic_background.module, line 612
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_image_selector_form($type = 'default', $data = -1) {
  $form = array(
    '#tree' => TRUE,
  );

  // Added extra information, which is used to extract information about the
  // image in the database.
  $form['dynamic_background_info'] = array(
    'type' => array(
      '#type' => 'hidden',
      '#value' => $type,
    ),
    'data' => array(
      '#type' => 'hidden',
      '#value' => $data,
    ),
  );

  // Load image information.
  $images = dynamic_background_load_images();
  $active_image = dynamic_background_active_image($type, $data);
  $settings = variable_get('dynamic_background_' . $type . '_image_style', array());
  foreach ($images as $fid => $image) {

    // Create image thumbnail.
    $thumb = array(
      'style_name' => isset($settings['thumbnail_style']) && $settings['thumbnail_style'] ? $settings['thumbnail_style'] : 'thumbnail',
      'path' => $image,
      'alt' => basename($image),
      'title' => basename($image),
    );
    $thumb = theme('image_style', $thumb);
    $form[$fid]['image'] = array(
      '#markup' => $thumb,
      '#prefix' => '<div class="dynamic-background-picture">',
    );
    $form[$fid]['selected'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use background'),
      '#default_value' => $active_image && $active_image->fid == $fid ? 1 : 0,
      '#suffix' => '</div>',
    );
  }

  // Add some default styling to the image selector.
  drupal_add_css(drupal_get_path('module', 'dynamic_background') . '/css/dynamic_background.theme.css');
  drupal_add_js(drupal_get_path('module', 'dynamic_background') . '/js/dynamic_background_selector.js');

  // Allow other modules to modify the form above using
  // hook_dynamic_background_selector_alter().
  drupal_alter('dynamic_background_selector', $form, $settings);
  return $form;
}