Drupal 7 Drupal 7模块中的主题切换(移动工具)

Drupal 7 Drupal 7模块中的主题切换(移动工具),drupal-7,Drupal 7,我一直在尝试让Drupal7的移动工具工作,但它似乎没有切换主题。(或者至少我无法让它切换) 这是“负责更改为移动主题”的代码。如果我打印$custom_theme,它确实会成为移动主题的名称,但显示的主题仍然是默认主题。我找不到任何关于变量$custom_theme的文档,至少Drupal 7没有 /** * Being called in the hook_boot() implementation * This function is in charge of changing to

我一直在尝试让Drupal7的移动工具工作,但它似乎没有切换主题。(或者至少我无法让它切换)

这是“负责更改为移动主题”的代码。如果我打印$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;
}

$custom_theme
不再是页面中提到的在Drupal 7中切换主题的方法,您必须使用或指定路径的
主题回调


示例来自:



我将尝试发帖。作为临时工,我安装了switchtheme模块,并将
$custom\u theme
更改为
$\u会话['custom\u theme']
哪个切换主题用于切换主题,但它在第一页请求中没有这样做,这意味着在mobile_toolsOk之前调用了switchtheme模块,因此在这些基础之上似乎存在一些问题。如果l()在hook_custom_主题模块之前被另一个模块调用它无法再更改主题,因为它已被启动。因此,您必须更改模块权重,并确保更改主题的模块位于第一个模块中。即使更改模块权重后,我也遇到了问题,因此我只是禁用了所有额外的模块并对其进行了测试(成功)然后我一次只启用一个或两个模块。当我让所有模块备份时,它一直在工作,所以我不确定它是如何工作的,但到目前为止它确实工作了。希望它能帮助其他人。
<?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';
  }
}
?>