You are here

function parallax_admin_settings_form in Parallax Toolkit 7.2

1 string reference to 'parallax_admin_settings_form'
parallax_admin_menu in parallax_admin/parallax_admin.module
Implements hook_menu().

File

parallax_admin/parallax_admin.module, line 18

Code

function parallax_admin_settings_form($form, &$form_state, $no_js_use = FALSE) {

  // Get all values from parallax_admin table
  $result = db_query("SELECT * FROM {parallax_admin}");
  $pdb = $result
    ->fetchAll();
  $form['#tree'] = TRUE;
  $form['parallax_fieldset'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="parallax-fieldset-wrapper">',
    '#suffix' => '</div>',
  );

  // If the table has values, get the number of rows. We do this so the form has
  // the appropriate number of fieldsets to populate
  if (empty($form_state['num_items'])) {
    $form_state['num_items'] = count($pdb);
  }
  for ($i = 0; $i < $form_state['num_items']; $i++) {
    $fieldset_background = $i % 2 == 0 ? "#FFFFFF" : "#F6F6F2";
    $form['parallax_fieldset'][$i] = array(
      '#title' => isset($pdb[$i]->identifier) ? $pdb[$i]->identifier : 'Parallax item ' . ($i + 1),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array(
        'style' => array(
          'background-color: ' . $fieldset_background . ';',
        ),
      ),
      'identifier' => array(
        '#title' => t('Identifier'),
        '#type' => 'textfield',
        '#default_value' => isset($pdb[$i]->identifier) ? $pdb[$i]->identifier : 'Parallax item ' . ($i + 1),
        '#description' => 'This field is only used as an label on this page, to uniquely identify each parallax item.',
      ),
      'selector' => array(
        '#title' => t('Selector'),
        '#type' => 'textfield',
        '#default_value' => isset($pdb[$i]->selector) ? $pdb[$i]->selector : '',
        '#description' => 'You can use any CSS/jQuery selector here that you like. Please note that advanced CSS3 selectors such as :not might have limited support.',
      ),
      'vertical_value' => array(
        '#title' => t('Vertical Parallax Direction'),
        '#type' => 'select',
        '#default_value' => isset($pdb[$i]->vertical_value) ? $pdb[$i]->vertical_value : 'none',
        '#options' => array(
          'none' => t('None'),
          'top-to-bottom' => t('Move to bottom on scroll (fast effect)'),
          'bottom-to-top' => t('Move to top on scroll (slow effect)'),
        ),
      ),
      'horizontal_value' => array(
        '#title' => t('Horizontal Parallax Direction'),
        '#type' => 'select',
        '#default_value' => isset($pdb[$i]->horizontal_value) ? $pdb[$i]->horizontal_value : 'none',
        '#options' => array(
          'none' => t('None'),
          'left-to-right' => t('Move to left on scroll'),
          'right-to-left' => t('Move to right on scroll'),
        ),
      ),
      'background_image' => array(
        '#title' => t('Background Image'),
        '#type' => 'managed_file',
        '#description' => t('Replace all spaces in file name with dashes. Larger pictures are recommended.'),
        '#default_value' => isset($pdb[$i]->background_image) ? $pdb[$i]->background_image : '',
        '#upload_location' => 'public://parallax_admin/',
        '#upload_validators' => array(
          'file_validate_extensions' => array(
            'gif png jpg jpeg',
          ),
          'file_validate_size' => array(
            2 * 1024 * 1024,
          ),
        ),
      ),
      'background_size' => array(
        '#title' => t('Background Size'),
        '#type' => 'textfield',
        '#size' => 60,
        '#default_value' => isset($pdb[$i]->background_size) ? $pdb[$i]->background_size : 'none',
        '#description' => t('Acceptable values are none, cover, contain, or percentages/pixels in the form of "200px" and "200%". If there is no effect, try altering this value.'),
        '#maxlength' => 20,
      ),
    );
  }
  $form['parallax_fieldset']['add_item'] = array(
    '#type' => 'submit',
    '#value' => t('Add item'),
    '#submit' => array(
      'parallax_admin_add_one',
    ),
    '#ajax' => array(
      'callback' => 'parallax_admin_callback',
      'wrapper' => 'parallax-fieldset-wrapper',
    ),
  );
  if ($form_state['num_items'] > 1) {
    $form['parallax_fieldset']['remove_item'] = array(
      '#type' => 'submit',
      '#value' => t('Remove item'),
      '#submit' => array(
        'parallax_admin_remove_one',
      ),
      '#ajax' => array(
        'callback' => 'parallax_admin_callback',
        'wrapper' => 'parallax-fieldset-wrapper',
      ),
    );
  }
  $final_form = system_settings_form($form);
  array_push($final_form['#submit'], 'parallax_admin_submit');
  return $final_form;
}