You are here

function form_styler_admin_form in jQuery form styler 7.2

Same name and namespace in other branches
  1. 7 form_styler.module \form_styler_admin_form()

Administration page callbacks for the form_styler module.

1 string reference to 'form_styler_admin_form'
form_styler_menu in ./form_styler.module
Implements hook_menu().

File

./form_styler.module, line 89
Attach jQuery form styler plugin to selected forms.

Code

function form_styler_admin_form($form, $form_state) {
  $library = libraries_detect('jquery_form_styler');
  if (empty($library['installed'])) {
    $error_message = isset($library['error message']) ? $library['error message'] : '';
    $placeholders = array(
      '!error' => $error_message,
      '!form_styler' => l(t('jQuery form styler plugin'), $library['download url']),
      '%path' => 'sites/all/libraries',
    );
    $message = t('!error You need to download the !form_styler, extract the archive, rename it to "jquery_form_styler" and place the plugin directory in the %path directory on your server.', $placeholders);
    drupal_set_message($message, 'error');
    return array();
  }

  // Vertical Tabs group.
  $form['form_styler'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );

  // Create settings form fieldsets.
  $form['plugin'] = array(
    '#type' => 'fieldset',
    '#title' => t('Main settings and performance'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#group' => 'form_styler',
  );
  $form['themes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Theme Overrides'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'form_styler',
  );
  $description_options = array(
    '!plugin_link' => url($library['vendor url'], array(
      'externak' => TRUE,
    )),
  );
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('JS settigns'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'form_styler',
    '#description' => t('Allow to chage default options of plugin. More information about options you can see at <a href="!plugin_link">Plugin page</a>.', $description_options),
  );

  // Textfield for form ids.
  $form['plugin']['form_styler_ids'] = array(
    '#title' => t('Form ids'),
    '#type' => 'textarea',
    '#description' => t('Specify the id of form for which you want to use form styler'),
    '#default_value' => variable_get('form_styler_ids', ''),
  );

  // Allow users to select form styler plugin variant.
  $form['plugin']['form_styler_variants'] = array(
    '#title' => t('Select variant'),
    '#type' => 'radios',
    '#options' => array(
      'minified' => t('Compressed'),
      'source' => t('Uncompressed'),
      'onlyjs' => t('Only compressed js (without css)'),
    ),
    '#description' => t('Select variants for attaching form styler'),
    '#default_value' => variable_get('form_styler_variants', 'minified'),
  );

  // Get Theme overrides information.
  $themes = list_themes();
  $theme_default = variable_get('theme_default', FALSE);
  $admin_theme = variable_get('admin_theme', FALSE);

  // Header form theme ovverides table.
  $header = array(
    t('Theme'),
    t('Status'),
    t('Operations'),
  );
  $rows = array();
  $link_options = array(
    'query' => drupal_get_destination(),
    'fragment' => 'edit-form-styler',
  );
  foreach ($themes as $theme_key => $theme) {

    // Skip disabled themes, but only if they are not configured as admin
    // theme. This is an inconsistency in drupal core, that you can select a
    // disabled theme as admin theme.
    if (!$theme->status && $theme_key !== $admin_theme) {
      continue;
    }
    $theme_name = $theme->info['name'];

    // Provide additional information for default and admin themes.
    if ($theme_key === $theme_default && ($theme_key === $admin_theme || empty($admin_theme))) {
      $theme_name .= ' (' . t('default/admin theme') . ')';
    }
    elseif ($theme_key === $theme_default) {
      $theme_name .= ' (' . t('default theme') . ')';
    }
    elseif ($theme_key === $admin_theme) {
      $theme_name .= ' (' . t('admin theme') . ')';
    }
    $status = theme_get_setting('form_styler_all_forms', $theme_key);

    // Create the table rows.
    $rows[] = array(
      $theme_name,
      $status ? t('Enabled on all forms') : t('Disabled'),
      l(t('Configure'), 'admin/appearance/settings/' . $theme_key, $link_options),
    );
  }

  // Attach theme overrides information table to form.
  $form['themes']['overrides'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  $default_options = form_styler_get_default_options();
  foreach ($default_options as $option_name => $option) {
    $type = isset($option['type']) ? $option['type'] : 'textfield';
    $option_key = 'form_styler_opt_' . $option_name;
    $form['options'][$option_key] = array(
      '#type' => $type,
      '#title' => $option['title'],
      '#default_value' => variable_get($option_key, $option['default']),
    );
    if (isset($option['description'])) {
      $form['options'][$option_key]['#description'] = $option['description'];
    }
    if (isset($option['related'])) {
      $form['options'][$option_key]['#states'] = array(
        'visible' => array(
          ':input[name="form_styler_opt_' . $option['related']['field'] . '"]' => $option['related']['condition'],
        ),
      );
    }
  }
  return system_settings_form($form);
}