You are here

function pagerer_preset_form in Pagerer 7

Preset edit form.

1 string reference to 'pagerer_preset_form'
pagerer_menu in ./pagerer.module
Implements hook_menu().

File

./pagerer.admin.inc, line 111
Pagerer administration

Code

function pagerer_preset_form($form, &$form_state) {

  // Add Pagerer's css.
  drupal_add_css(drupal_get_path('module', 'pagerer') . '/pagerer.css');

  // Get pagerer preset.
  $preset = _pagerer_get_preset($form_state['build_info']['args'][0]);

  // Check if jQuery update is installed.
  if (module_exists('jquery_update')) {
    $js_enabled = TRUE;
  }
  else {
    $js_enabled = FALSE;
    drupal_set_message(t("To enable the jQuery based themes 'pagerer_mini', 'pagerer_slider' and 'pagerer_scrollpane', Pagerer requires the 'jQuery update' module to be installed and enabled."), 'status', FALSE);
  }

  // List of the themes available for panes.
  $options = array(
    'none',
    'pagerer_standard',
    'pagerer_progressive',
    'pagerer_adaptive',
  );

  // Mini, Slider and Scrollpane are only available with jQuery update
  // installed.
  if ($js_enabled) {
    $options = array_merge($options, array(
      'pagerer_mini',
      'pagerer_slider',
      'pagerer_scrollpane',
    ));
  }
  $options = drupal_map_assoc($options);

  // Panes configuration.
  $form['panes_container'] = array(
    '#type' => 'fieldset',
    '#title' => t("Panes configuration"),
    '#description' => t("Select the themes to be rendered in each Pagerer pane. Click 'Configure' to change each theme behaviour. Click 'Reset' to reset a pane configuration to its theme's default."),
  );

  // Table container to render the 3 pane config boxes inline.
  $form['panes_container']['panes'] = array(
    '#tree' => TRUE,
    '#title' => t("Panes"),
    '#theme' => 'table',
    '#header' => array(),
    '#rows' => array(),
    '#attributes' => array(
      'class' => array(
        'pagerer_admin_panes_config',
      ),
    ),
  );

  // Left pane.
  $left_pane = array(
    '#type' => 'fieldset',
    '#title' => t("Left pane"),
  );
  $left_pane['theme_name'] = array(
    '#type' => 'select',
    '#title' => t("Theme"),
    '#options' => $options,
    '#default_value' => $preset['left_pane']['theme_name'],
  );
  $left_pane['configure'] = array(
    '#type' => 'submit',
    '#name' => 'config_left',
    '#value' => t("Configure"),
  );
  $left_pane['reset'] = array(
    '#type' => 'submit',
    '#name' => 'reset_left',
    '#value' => t("Reset"),
  );

  // Center pane.
  $center_pane = array(
    '#type' => 'fieldset',
    '#title' => t("Center pane"),
  );
  $center_pane['theme_name'] = array(
    '#type' => 'select',
    '#title' => t("Theme"),
    '#options' => $options,
    '#default_value' => $preset['center_pane']['theme_name'],
  );
  $center_pane['configure'] = array(
    '#type' => 'submit',
    '#name' => 'config_center',
    '#value' => t("Configure"),
  );
  $center_pane['reset'] = array(
    '#type' => 'submit',
    '#name' => 'reset_center',
    '#value' => t("Reset"),
  );

  // Right pane.
  $right_pane = array(
    '#type' => 'fieldset',
    '#title' => t("Right pane"),
  );
  $right_pane['theme_name'] = array(
    '#type' => 'select',
    '#title' => t("Theme"),
    '#options' => $options,
    '#default_value' => $preset['right_pane']['theme_name'],
  );
  $right_pane['configure'] = array(
    '#type' => 'submit',
    '#name' => 'config_right',
    '#value' => t("Configure"),
  );
  $right_pane['reset'] = array(
    '#type' => 'submit',
    '#name' => 'reset_right',
    '#value' => t("Reset"),
  );

  // Container elements - FAPI accessible.
  $form['panes_container']['panes']['e'] = array(
    'left' => array(
      'data' => &$left_pane,
    ),
    'center' => array(
      'data' => &$center_pane,
    ),
    'right' => array(
      'data' => &$right_pane,
    ),
  );

  // Container elements - to render the table.
  $form['panes_container']['panes']['#rows'][0] = array(
    array(
      'data' => &$left_pane,
    ),
    array(
      'data' => &$center_pane,
    ),
    array(
      'data' => &$right_pane,
    ),
  );

  // Pagerer's preview.
  pager_default_initialize(47884, 50);
  $form['preview'] = array(
    '#type' => 'fieldset',
    '#title' => t("Pagerer preview"),
  );
  $form['preview']['pagerer'] = array(
    '#markup' => theme('pagerer', array(
      'left_pane' => $preset['left_pane'],
      'center_pane' => $preset['center_pane'],
      'right_pane' => $preset['right_pane'],
    )),
  );

  // Save configuration.
  $form['save'] = array(
    '#type' => 'submit',
    '#name' => 'save',
    '#value' => t("Update"),
  );
  $form['save_return'] = array(
    '#type' => 'submit',
    '#name' => 'save_return',
    '#value' => t("Save and return"),
  );
  return $form;
}