You are here

function rate_ui_widget_form_step_buttons in Rate 7.2

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

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

File

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

Code

function rate_ui_widget_form_step_buttons($form, &$form_state, $widget_type = NULL) {
  $form['buttons'] = array(
    '#prefix' => '<div id="rate-buttons">',
    '#suffix' => '</div>',
  );
  $form['buttons']['list'] = array(
    '#theme' => 'rate_ui_buttons',
  );

  // Set or update the number of buttons.
  !empty($form_state['storage']['buttoncount']) or $form_state['storage']['buttoncount'] = 2;
  switch ($form_state['triggering_element']['#value']) {
    case t('Add'):
      ++$form_state['storage']['buttoncount'];
      break;
    case t('Remove'):
      --$form_state['storage']['buttoncount'];
      break;
  }

  // Create form elements for buttons.
  for ($i = 1; $i <= $form_state['storage']['buttoncount']; ++$i) {
    $form['buttons']['list'][$i] = array();
    $form['buttons']['list'][$i]["button{$i}_label"] = array(
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#size' => 16,
      '#default_value' => isset($form_state['storage']["button{$i}_label"]) ? $form_state['storage']["button{$i}_label"] : '',
    );
    $form['buttons']['list'][$i]["button{$i}_value"] = array(
      '#type' => 'textfield',
      '#title' => t('Value'),
      '#size' => 6,
      '#default_value' => isset($form_state['storage']["button{$i}_value"]) ? $form_state['storage']["button{$i}_value"] : '',
    );
    $form['buttons']['list'][$i]["button{$i}_description"] = array(
      '#type' => 'textfield',
      '#title' => t('Description'),
      '#default_value' => isset($form_state['storage']["button{$i}_description"]) ? $form_state['storage']["button{$i}_description"] : '',
    );
  }
  $form['buttons']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
    '#submit' => array(
      'rate_ui_widget_form_submit',
    ),
    '#ajax' => array(
      'callback' => 'rate_ui_widget_form_ajax',
      'wrapper' => 'rate-buttons',
      'effect' => 'fade',
    ),
  );
  if ($form_state['storage']['buttoncount'] > 1) {
    $form['buttons']['remove'] = array(
      '#type' => 'submit',
      '#value' => t('Remove'),
      '#submit' => array(
        'rate_ui_widget_form_submit',
      ),
      '#ajax' => array(
        'callback' => 'rate_ui_widget_form_ajax',
        'wrapper' => 'rate-buttons',
        'effect' => 'fade',
      ),
    );
  }

  // Add formfields for the revoke button.
  $form['buttons']['revoke'] = array(
    '#type' => 'fieldset',
    '#title' => t('Revoke button'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['buttons']['revoke']['fields'] = array(
    '#theme' => 'rate_ui_buttons',
  );
  $form['buttons']['revoke']['fields'][0] = array();
  $form['buttons']['revoke']['fields'][0]["button0_label"] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#size' => 16,
    '#default_value' => isset($form_state['storage']["button0_label"]) ? $form_state['storage']["button0_label"] : '',
  );
  $form['buttons']['revoke']['fields'][0]["button0_value"] = array(
    '#markup' => t('N/A'),
  );
  $form['buttons']['revoke']['fields'][0]["button0_description"] = array(
    '#type' => 'textfield',
    '#title' => t('Description'),
    '#default_value' => isset($form_state['storage']["button0_description"]) ? $form_state['storage']["button0_description"] : '',
  );
  $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;
}