You are here

function views_sexy_throbber_settings in Views Sexy Throbber 7.2

Create the settings page form.

1 string reference to 'views_sexy_throbber_settings'
views_sexy_throbber_menu in ./views_sexy_throbber.module
Implements hook_menu().

File

./settings_form.inc, line 11
Settings form for Views Sexy Throbber.

Code

function views_sexy_throbber_settings($form, &$form_state) {

  // Include the views sexy throbber variables.
  include 'variables.inc';

  // Load the admin css to make the form prettier.
  drupal_add_css($module_directory . '/css/admin-form.css');

  // Check if the custom throbber directory exist and if not create it.
  if (!file_prepare_directory($user_directory, $options = FILE_CREATE_DIRECTORY)) {
    drupal_set_message(t('Notice: There was a problem creating the custom images directory. Please make sure your public folder is writable by Drupal and reinstall the module. You can also ignore this notice and use only the images provided by the module, or you can create the custom image folder manually. The folder must be named “views_sexy_throbber” and must be placed in your public directory. If you need more help please use the module issue page or read the documentation.'), 'warning', TRUE);
  }

  // Scan for throbber images.
  $throbber_images = file_scan_directory($user_directory, '/^.*\\.(jpg|gif|png)$/');

  // Set default options for "$form['image']['views_sexy_throbber_image']".
  $image_options = array(
    $default_image => theme('image', array(
      'path' => $user_directory . "/" . $default_image,
    )),
  );

  // Add all images to the radio form.
  foreach ($throbber_images as $image_file) {
    $image_file_uri = $image_file->uri;
    $image_options[$image_file->filename] = theme('image', array(
      'path' => $image_file_uri,
    ));
  }

  // Generate form elements.
  $form['overlay'] = array(
    '#type' => 'fieldset',
    '#title' => t('Page Overlay Settings'),
  );
  $form['overlay']['views_sexy_throbber_background'] = array(
    '#type' => 'select',
    '#title' => t('Overlay Background'),
    '#default_value' => variable_get('views_sexy_throbber_background', '0,0,0'),
    '#options' => array(
      '0,0,0' => t('Dark'),
      '255,255,255' => t('Light'),
    ),
    '#description' => t('Select overlay background color. <strong>Default value: Dark</strong>'),
    '#required' => TRUE,
  );
  $form['overlay']['views_sexy_throbber_opacity'] = array(
    '#type' => 'select',
    '#title' => t('Overlay Opacity'),
    '#default_value' => variable_get('views_sexy_throbber_opacity', '0.3'),
    '#options' => array(
      '0' => t('0%'),
      '0.1' => t('10%'),
      '0.2' => t('20%'),
      '0.3' => t('30%'),
      '0.4' => t('40%'),
      '0.5' => t('50%'),
      '0.6' => t('60%'),
      '0.7' => t('70%'),
      '0.8' => t('80%'),
      '0.9' => t('90%'),
      '1' => t('100%'),
    ),
    '#description' => t('Select the overlay opacity percentage. <strong>Default value: 30%</strong>'),
    '#required' => TRUE,
  );
  $form['image'] = array(
    '#type' => 'fieldset',
    '#title' => t('Throbber Image'),
  );
  $form['image']['views_sexy_throbber_image'] = array(
    '#type' => 'radios',
    '#title' => t('Select throbber image'),
    '#default_value' => variable_get('views_sexy_throbber_image', $default_image),
    '#options' => $image_options,
    '#description' => t('Do you want to add your own images? Upload them to <span class="path">@custom_throbbers_directory</span> and refresh this page.', array(
      '@custom_throbbers_directory' => str_replace($base_url . '/', "", file_create_url($user_directory)),
    )),
    '#required' => TRUE,
  );
  $form['image']['views_sexy_throbber_image_background'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add solid color background to the image'),
    '#description' => t("This will add a solid background color to the throbber image (pure black for the dark overlay, and pure white for the light). This is useful if you are using gif images that don't handle transparency very well. <strong>Default value: checked</strong>"),
    '#default_value' => variable_get('views_sexy_throbber_image_background', TRUE),
  );
  $form['image']['views_sexy_throbber_image_background_use_border_radius'] = array(
    '#type' => 'checkbox',
    '#title' => t('Apply "Rounded corners" effect to the image background'),
    '#description' => t('You can make round corners by adding border radius to the background box. <strong>Default value: checked</strong>'),
    '#default_value' => variable_get('views_sexy_throbber_image_background_use_border_radius', TRUE),
    '#states' => array(
      'visible' => array(
        ':input[name="views_sexy_throbber_image_background"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['image']['views_sexy_throbber_image_background_border_radius'] = array(
    '#type' => 'textfield',
    '#title' => t('Rounded corners border radius'),
    '#description' => t('Enter a number from "0" to "999" representing the border radius in pixels. Greater number, means more rounded corners. <strong>Default value: 16</strong>'),
    '#default_value' => variable_get('views_sexy_throbber_image_background_border_radius', '16'),
    '#empty_value' => '0',
    '#size' => 3,
    '#maxlength' => 3,
    '#states' => array(
      'visible' => array(
        ':input[name="views_sexy_throbber_image_background_use_border_radius"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
    '#field_suffix' => t('pixels'),
    '#element_validate' => array(
      'views_sexy_throbber_valdate_border_radius',
    ),
    '#required' => TRUE,
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced Settings'),
  );
  $form['advanced']['views_sexy_throbber_use_in_other_modules'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use Views Sexy Throbber in other modules'),
    '#description' => t('This will attempt to replace the default Drupal throbber and apply it to other modules too. (Removes the ".view" class from the css selector) <strong>Default value: unchecked</strong>'),
    '#default_value' => variable_get('views_sexy_throbber_use_in_other_modules', FALSE),
  );
  $form['advanced']['views_sexy_throbber_append_important'] = array(
    '#type' => 'checkbox',
    '#title' => t('Append css !important rules'),
    '#description' => t('Check this box if sexy throbber conflicts with other styles or you are having display issues. This will force the css styling to be overridden by appending !important rules. <strong>Default value: unchecked</strong>'),
    '#default_value' => variable_get('views_sexy_throbber_append_important', FALSE),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}