You are here

function mobile_switch_settings_form in Mobile Switch 7.2

Same name and namespace in other branches
  1. 6 includes/mobile_switch.admin.inc \mobile_switch_settings_form()
  2. 7 includes/mobile_switch.admin.inc \mobile_switch_settings_form()

Form constructor for the Basic settings form.

1 string reference to 'mobile_switch_settings_form'
mobile_switch_menu in ./mobile_switch.module
Implements hook_menu().

File

includes/mobile_switch.admin.inc, line 12
Administrative page callbacks for the Mobile Switch module.

Code

function mobile_switch_settings_form() {
  $form = array();

  // Current local Mobile Detect class version.
  $library['version'] = FALSE;
  $library_path = libraries_get_path(MOBILE_SWITCH_LIBRARY_NAME, $base_path = FALSE);
  $library_uri = $library_path . '/' . MOBILE_SWITCH_LIBRARY_FILE_NAME;
  if ($library_path) {
    $library['version'] = mobile_switch_mobile_detect_get_version($library_uri);
  }
  if (!$library_path || !file_exists($library_uri) || !$library['version']) {
    $form['library_missing'] = array(
      '#markup' => '<p>' . t('The Mobile Detect class could not be found as library. See README.txt for installation instructions.') . '</p>',
    );
    return $form;
  }
  else {
    $form['library_exist'] = array(
      '#markup' => '<p>' . t('Currently used Mobile Detect version: %fileversion', array(
        '%fileversion' => $library['version'],
      )) . '</p>',
    );
  }
  $module_path = drupal_get_path('module', 'mobile_switch');
  drupal_add_js($module_path . '/js/mobile_switch.admin.js', array(
    'scope' => 'footer',
  ));

  // Add operating modes.
  $active_themes = array_merge(array(
    'none' => t('Do not use'),
    'detectonly' => t('No theme switch - detect only'),
    'redirect' => t('No theme switch - redirect to website'),
  ), mobile_switch_get_themes());

  // Check the imported/fetched Mobile Detect class version number.
  $version = variable_get('mobile_detect_import_version', 0);
  $form['global_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Operating mode.
  $form['global_settings']['mobile_switch_mobile_theme'] = array(
    '#type' => 'select',
    '#title' => t('Operating mode'),
    '#description' => t('Select the operating mode or the theme which should be used as default theme when a mobile device detected.'),
    '#options' => $active_themes,
    '#default_value' => variable_get('mobile_switch_mobile_theme', 'none'),
  );

  // Redirect URL's usage message.
  $form['global_settings']['mobile_switch_redirect_url_message'] = array(
    '#markup' => '<div class="form-item form-item-mobile-switch-redirect-url-message" style="display: none;"><label for="form-item form-item-mobile-switch-redirect-url-message">' . t("Redirect URL's") . '</label><div class="description">' . t("Important: Use the same URL's that are defined in the setting.php files as <em>Base URL</em>.") . '</div></div>',
  );

  // Redirect URL to mobile.
  $form['global_settings']['mobile_switch_redirect_url_to_mobile'] = array(
    '#type' => 'textfield',
    '#title' => t('Redirect URL to mobile'),
    '#default_value' => variable_get('mobile_switch_redirect_url_to_mobile', ''),
    '#description' => t('The <em>Base URL</em> of the mobile website to which should be redirected. Must begin with http:// and not use a trailing slash.'),
    '#element_validate' => array(
      '_mobile_switch_redirect_url_to_mobile_validate',
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="mobile_switch_mobile_theme"]' => array(
          'value' => 'redirect',
        ),
      ),
    ),
  );

  // Redirect URL to desktop.
  $form['global_settings']['mobile_switch_redirect_url_to_desktop'] = array(
    '#type' => 'textfield',
    '#title' => t('Redirect URL to desktop'),
    '#default_value' => variable_get('mobile_switch_redirect_url_to_desktop', ''),
    '#description' => t('The <em>Base URL</em> of the desktop website to which should be redirected. Must begin with http:// and not use a trailing slash.'),
    '#element_validate' => array(
      '_mobile_switch_redirect_url_to_desktop_validate',
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="mobile_switch_mobile_theme"]' => array(
          'value' => 'redirect',
        ),
      ),
    ),
  );

  // Tablet usage.
  $form['global_settings']['mobile_switch_tablet_usage'] = array(
    '#type' => 'select',
    '#title' => t('Tablet device'),
    '#description' => t('Use the Mobile Switch functionality when a mobile device tablet detected.'),
    '#options' => array(
      TRUE => t('Yes'),
      FALSE => t('No'),
    ),
    '#default_value' => variable_get('mobile_switch_tablet_usage', 1),
  );

  // Administration usage.
  $form['global_settings']['mobile_switch_admin_usage'] = array(
    '#type' => 'select',
    '#title' => t('Administration usage'),
    '#description' => t('Use the Mobile Switch functionality on administration pages when a mobile device detected.'),
    '#options' => array(
      FALSE => t('No'),
      TRUE => t('Yes'),
    ),
    '#default_value' => variable_get('mobile_switch_admin_usage', 0),
  );
  $form['#submit'][] = 'mobile_switch_settings_form_submit';
  return system_settings_form($form);
}