You are here

function mostpopular_intervals_admin_form in Drupal Most Popular 7

1 string reference to 'mostpopular_intervals_admin_form'
mostpopular_menu in ./mostpopular.module
Implements hook_menu().

File

./mostpopular.intervals.inc, line 19
Provides an admin GUI for configuring intervals.

Code

function mostpopular_intervals_admin_form($form, &$form_state) {
  $form += array(
    '#tree' => TRUE,
    'blocks' => array(
      '#theme' => 'mostpopular_admin_intervals_table',
    ),
  );
  $blocks = mostpopular_blocks_local();
  $form_state['blocks'] = $blocks;
  $block_options = array();
  foreach ($blocks as $bid => $block) {
    $block_options[$bid] = $block->title;
  }
  foreach ($blocks as $bid => $block) {
    $form['blocks'][$bid] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Block: @title', array(
        '@title' => $block->title,
      )),
      'bid' => array(
        '#type' => 'hidden',
        '#value' => $bid,
      ),
      'intervals' => array(
        '#tree' => TRUE,
      ),
    );
    if (!isset($form_state['intervals'][$bid])) {
      $form_state['intervals'][$bid] = mostpopular_interval_load_by_block($bid);
    }

    // If there are no intervals for this block, create some default ones.
    if (empty($form_state['intervals'][$bid])) {
      $form_state['intervals'][$bid] = mostpopular_interval_defaults($bid);
    }
    foreach ($form_state['intervals'][$bid] as $iid => $interval) {
      $form['blocks'][$bid]['intervals'][$iid] = array(
        'id' => array(
          '#markup' => !empty($interval->iid) ? $interval->iid : t('New'),
        ),
        'title' => array(
          '#type' => 'textfield',
          '#size' => 32,
          '#default_value' => check_plain($interval->title),
        ),
        'string' => array(
          '#type' => 'textfield',
          '#size' => 32,
          '#default_value' => check_plain($interval->string),
        ),
        'weight' => array(
          '#type' => 'textfield',
          '#size' => 3,
          '#default_value' => isset($interval->weight) ? $interval->weight : count($form_state['intervals'][$bid]),
        ),
        'bid' => array(
          '#type' => 'select',
          '#default_value' => $bid,
          '#options' => $block_options,
        ),
      );
    }
    $form['blocks'][$bid]['add_button'] = array(
      '#type' => 'submit',
      '#value' => t('Add'),
      '#submit' => array(
        'mostpopular_intervals_admin_form_add',
      ),
      '#bid' => $bid,
      '#name' => "add_button[{$bid}]",
    );
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'mostpopular_intervals_admin_form_submit',
    ),
  );
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to Default Configuration'),
    '#attributes' => array(
      'onclick' => 'javascript:return confirm("' . t("This will reset all the intervals and all the cached most popular data.  Are you sure you want to do this?") . '");',
    ),
    '#weight' => 101,
    '#submit' => array(
      'mostpopular_intervals_admin_form_reset',
    ),
  );
  return $form;
}