You are here

function rate_ui_widget_form_step_images in Rate 7.2

Generate form fields for the fifth step in the rate widget form.

1 call to rate_ui_widget_form_step_images()
rate_ui_widget_form in ui/rate_ui.form.inc
Implements hook_form().

File

ui/rate_ui.form.inc, line 392
This file contains the differtent Rate UI forms.

Code

function rate_ui_widget_form_step_images($form, &$form_state, $widget_type = NULL) {
  $sprites = $form_state['storage']['sprites'];
  $separate = $form_state['storage']['separate_images'];
  $imagesource = $form_state['storage']['imagesource'];
  if ($imagesource == 'spritegenerator') {

    // Start with the revoke button?
    $start = empty($form_state['storage']['button0_label']) ? 1 : 0;
    $end = $form_state['storage']['buttoncount'];
    $form['sprites'] = rate_ui_sprite_classes_table($start, $end);
  }
  else {
    if ($sprites) {
      if ($imagesource == 'upload') {
        $form['sprite_file'] = array(
          '#type' => 'managed_file',
          '#title' => t('Sprite image'),
          '#upload_location' => 'public://rate',
          '#upload_validators' => array(
            'file_validate_extensions' => array(
              'jpg png gif',
            ),
          ),
          '#progress_indicator' => 'bar',
          '#pre_render' => array(
            'file_managed_file_pre_render',
          ),
          '#default_value' => isset($form_state['storage']['sprite_file']) ? $form_state['storage']['sprite_file'] : 0,
        );
      }
      elseif ($imagesource == 'filepath') {
        $form['sprite_filepath'] = array(
          '#type' => 'textfield',
          '#title' => t('Sprite image'),
          '#default_value' => isset($form_state['storage']['sprite_filepath']) ? $form_state['storage']['sprite_filepath'] : '',
          '#description' => t('Provide a filepath to the image, relative to the Drupal basedir. Do not use a leading slash.'),
        );
      }
    }
    $form['buttons'] = array();

    // Start with the revoke button?
    $start = empty($form_state['storage']['button0_label']) ? 1 : 0;

    // Separate images for each button?
    $end = $separate ? $form_state['storage']['buttoncount'] : 1;
    for ($i = $start; $i <= $end; ++$i) {
      if ($i == 0) {
        $title = t('Revoke button');
      }
      elseif (!$separate) {
        $title = t('Vote buttons');
      }
      else {
        if (empty($form_state['storage']["button{$i}_label"])) {

          // Label field is not filled in, do not use this button.
          continue;
        }
        $title = t('Button %label', array(
          '%label' => $form_state['storage']["button{$i}_label"],
        ));
      }
      $form['buttons'][$i] = array(
        '#type' => 'fieldset',
        '#title' => $title,
        '#collapsible' => TRUE,
      );
      if ($sprites) {
        $form['buttons'][$i]['#theme'] = 'rate_ui_sprites';
        $form['buttons'][$i]['#imagesource'] = $imagesource;
      }
      $kinds = array(
        'default',
        'highlighted',
        'default_voted',
        'highlighted_voted',
        'disabled',
        'disabled_voted',
      );
      foreach ($kinds as $kind) {
        $kind_name = str_replace('_', ' ', $kind);
        if ($sprites) {
          $form['buttons'][$i]["button{$i}_{$kind}"] = array(
            '#type' => 'fieldset',
            '#title' => t($kind_name),
          );
          $form['buttons'][$i]["button{$i}_{$kind}"]["button{$i}_{$kind}_x"] = array(
            '#type' => 'textfield',
            '#title' => t('X offset'),
            '#size' => 6,
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_x"]) ? $form_state['storage']["button{$i}_{$kind}_x"] : '',
          );
          $form['buttons'][$i]["button{$i}_{$kind}"]["button{$i}_{$kind}_y"] = array(
            '#type' => 'textfield',
            '#title' => t('Y offset'),
            '#size' => 6,
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_y"]) ? $form_state['storage']["button{$i}_{$kind}_y"] : '',
          );
          $form['buttons'][$i]["button{$i}_{$kind}"]["button{$i}_{$kind}_width"] = array(
            '#type' => 'textfield',
            '#title' => t('Width'),
            '#size' => 6,
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_width"]) ? $form_state['storage']["button{$i}_{$kind}_width"] : '',
          );
          $form['buttons'][$i]["button{$i}_{$kind}"]["button{$i}_{$kind}_height"] = array(
            '#type' => 'textfield',
            '#title' => t('Height'),
            '#size' => 6,
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_height"]) ? $form_state['storage']["button{$i}_{$kind}_height"] : '',
          );
        }
        elseif ($imagesource == 'upload') {
          $form['buttons'][$i]["button{$i}_{$kind}_file"] = array(
            '#type' => 'managed_file',
            '#title' => t($kind_name),
            '#upload_location' => 'public://rate',
            '#upload_validators' => array(
              'file_validate_extensions' => array(
                'jpg png gif',
              ),
            ),
            '#progress_indicator' => 'bar',
            '#pre_render' => array(
              'file_managed_file_pre_render',
            ),
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_file"]) ? $form_state['storage']["button{$i}_{$kind}_file"] : 0,
          );
        }
        elseif ($imagesource == 'filepath') {
          $form['buttons'][$i]["button{$i}_{$kind}_filepath"] = array(
            '#type' => 'textfield',
            '#title' => t($kind_name),
            '#default_value' => isset($form_state['storage']["button{$i}_{$kind}_filepath"]) ? $form_state['storage']["button{$i}_{$kind}_filepath"] : '',
            '#description' => t('Provide a filepath to the image, relative to the Drupal basedir. Do not use a leading slash.'),
          );
        }
      }
    }
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['previous'] = array(
    '#type' => 'submit',
    '#value' => t('Previous'),
  );
  $form['actions']['next'] = array(
    '#type' => 'submit',
    '#value' => t('Next'),
  );
  return $form;
}