You are here

function mobile_switch_form_alter in Mobile Switch 6

Implementation of hook_form_alter().

File

./mobile_switch.module, line 148
Simple theme switch for mobile devices, detected by browscap.

Code

function mobile_switch_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'system_themes_form':
      $mobile_theme = variable_get('mobile_switch_mobile_theme', 'none');
      $themes = mobile_switch_get_themes();

      // Provide JS function to disable the mobile theme checkbox
      // on the themes administration list page.
      drupal_add_js(array(
        'mobileSwitch' => array(
          'mobileTheme' => $mobile_theme,
        ),
      ), 'setting');
      drupal_add_js(drupal_get_path('module', 'mobile_switch') . '/js/mobile_switch.admin.js', 'module', 'footer');
      if ($mobile_theme !== 'none' && isset($themes[$mobile_theme])) {
        if (isset($form[$mobile_theme])) {

          // Prepare the mobile theme description.
          $mobile_theme_description = '<em>';
          $mobile_theme_description .= $form[$mobile_theme]['info']['#value']['description'];
          $mobile_theme_description .= '<br />' . t('(default mobile theme by !mobile-switch)', array(
            '!mobile-switch' => l(t('Mobile Switch'), 'admin/settings/mobile-switch', array(
              'attributes' => array(
                'title' => t('Administer Mobile Switch'),
              ),
            )),
          ));
          $mobile_theme_description .= '</em>';
          $form[$mobile_theme]['info']['#value']['description'] = $mobile_theme_description;
        }
      }

      // Alter default theme description.
      $theme_default = $form['theme_default']['#default_value'];
      $theme_default_description = '<em>';
      $theme_default_description .= $form[$theme_default]['info']['#value']['description'];
      $theme_default_description .= '</em>';
      $form[$theme_default]['info']['#value']['description'] = $theme_default_description;
      $form['#submit'][] = 'mobile_switch_system_themes_form_submit';
      break;
  }
}