You are here

function dynamic_background_user_upload_form in Dynamic Background 7.2

Hepler function that build an upload form, which can be used by sub-modules to allow uploading of files.

Parameters

type $type:

type $data:

type $number_of_files:

Return value

array

4 calls to dynamic_background_user_upload_form()
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.

File

./dynamic_background.module, line 678
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_user_upload_form($type = 'default', $data = -1, $number_of_files = 1) {
  $form = array();

  // Allow the form to upload files.
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  $form['dynamic_background_picture_upload'] = array(
    '#type' => 'fieldset',
    '#title' => t('Upload image'),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
    '#tree' => TRUE,
  );

  // Try to find uploaded file and build default value.
  $uploaded_images = dynamic_background_load_images($type, $data);
  $active_image = dynamic_background_active_image($type, $data);
  if ($active_image) {
    $active_image = $active_image->fid;
  }
  $i = 0;
  foreach ($uploaded_images as $fid => $uri) {
    $i++;
    $default = array(
      'picture' => $uri,
      'fid' => $fid,
      'picture_use' => $fid == $active_image ? 1 : 0,
      'picture_delete' => 0,
    );
    $form['dynamic_background_picture_upload'][$fid] = array(
      '#type' => 'background_upload_form',
      '#title' => t('Background image %num', array(
        '%num' => $i,
      )),
      '#default_value' => $default,
    );
  }

  // Add empty upload slots, if any left.
  for ($i - 1; $number_of_files > $i; $i++) {
    $form['dynamic_background_picture_upload'][$i + 1] = array(
      '#type' => 'background_upload_form',
      '#title' => t('Background image %num', array(
        '%num' => $i + 1,
      )),
      '#default_value' => array(),
    );
  }

  // Add some styling to the form.
  drupal_add_css(drupal_get_path('module', 'dynamic_background') . '/css/dynamic_background_user_upload.theme.css');

  // Return the $form and the validation function, it's done this way because
  // the validation function otherwise maybe overridden in the calling function.
  return array(
    'form' => $form,
    'submit' => 'dynamic_background_user_upload_form_submit',
  );
}