Переключение тем в модуле Drupal 7 (мобильные инструменты) - PullRequest
2 голосов
/ 01 марта 2011

Я пытался заставить работать mobile_tools для Drupal 7, но похоже, что он не переключает темы.(Или, по крайней мере, я не могу заставить его переключаться).

Это код, отвечающий за переход на мобильную тему. Если я печатаю $ custom_theme, он становится названием мобильной темы, но отображаемая тема по-прежнему используется по умолчанию.любая документация по переменной $ custom_theme как минимум не для Drupal 7.

/**
 * Being called in the hook_boot() implementation
 * This function is in charge of changing to the mobile theme
 */
function mobile_tools_switch_theme($device) {
 global $custom_theme, $conf;
 // check if theme switching is forced
 $current_url_type = mobile_tools_is_mobile_site();

 if (($current_url_type == 'mobile' &&  variable_get('mobile-tools-theme-switch', ''  ) == 'mobile-tools-mobile-url') || 
   (variable_get('mobile-tools-theme-switch', ''  ) == 'mobile-tools-mobile-device' && $device['type']  == 'mobile') ) {
  $group = $device['group'];
  $mobile_detection_module = variable_get('mobile-tools-device-detection', 'mobile_tools');
  if (variable_get($mobile_detection_module . '_' . $group . '_enable', '') == 1) {
   $custom_theme = variable_get($mobile_detection_module . '_' . $group . '_theme', $conf['theme_default']);
   return TRUE;
  }
  else {
   $custom_theme  = variable_get('mobile_tools_theme_name', $conf['theme_default']);
   return TRUE;
  }
 }
 return FALSE;
}

1 Ответ

1 голос
/ 01 марта 2011

$custom_theme больше не является способом переключения тем в Drupal 7, как упоминалось на странице Обновление модулей с 6.x до 7.x , вы должны использовать hook_custom_theme или вместо него укажите theme callback.


Пример со страницы обновления :

<?php
/**
* Implements hook_menu_alter().
*/
function mymodule_menu_alter(&$items) {
  // Set the theme callback function for all node pages. As per the
  // standard behavior for hook_menu() properties, this will be
  // inherited by all paths underneath node/%node as well, unless
  // they define their own theme callback.
  $items['node/%node']['theme callback'] = 'mymodule_default_node_theme';

  // Set a different theme callback for node edit pages, and pass
  // along the node object to this function so we can make decisions
  // based on it.
  $items['node/%node/edit']['theme callback'] = 'mymodule_edit_node_theme';
  $items['node/%node/edit']['theme arguments'] = array(1);
}

/**
* Defaults to using the 'some_theme' theme for node pages.
*/
function mymodule_default_node_theme() {
  return 'some_theme';
}

/**
* For editing page nodes, uses the 'some_other_theme' theme.
*/
function mymodule_edit_node_theme($node) {
  return $node->type == 'page' ? 'some_other_theme' : mymodule_default_node_theme();
}

/**
* Implements hook_custom_theme().
*/
function mymodule_custom_theme() {
  global $user;
  // If the current user has a special role assigned to them, then display all
  // pages of the site (including those listed above) using the 'special_theme'
  // theme.
  if (in_array(variable_get('mymodule_special_role', 0), array_keys($user->roles))) {
    return 'special_theme';
  }
}
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...