2013-10-24 37 views
1

有誰知道編程節點後編程使用默認主題從模塊渲染視圖的方法嗎?Drupal:從管理使用前端主題渲染視圖

我基本上試圖創建一個視圖的靜態html頁面。

我有一個自定義模塊以下代碼:

function MODULENAME_node_update($node) { 
    unset($node->is_new); 
    unset($node->original);  
    entity_get_controller('node')->resetCache(array($node->nid)); 
    $view = views_get_view('references'); 
    $view->set_display('block'); 
    $output = $view->render(); 
    file_put_contents('references.html', $output); 
} 

代碼的作品,但由於顯而易見的原因,使得使用管理主題的看法。

我已經試過幾件事情都無濟於事:

variable_set

function MODULENAME_node_update($node) { 
    variable_set('admin_theme', 'DEFAULT THEME HERE'); 
    [...] 
    variable_set('admin_theme', 'ADMIN THEME HERE'); 
} 

該掛鉤可能是不被調用時爲時已晚,這對切換主題正確的地方。

全球$ custom_theme

function MODULENAME_node_update($node) { 
    global $custom_theme; 
    $custom_theme = 'DEFAULT THEME HERE'; 
    [...] 
    $custom_theme = 'ADMIN THEME HERE'; 
} 

自定義菜單項

function MODULE_NAME_menu(){ 
    $items = array(); 

    $items['outputview'] = array(
    'title' => 'Test', 
    'type' => MENU_CALLBACK, 
    'page callback' => 'MODULE_NAME_output_view', 
    'access callback' => TRUE, 
    'theme callback' => 'DEFAULT THEME HERE' 
); 

    return $items; 
} 

function MODULE_NAME_output_view() { 
    $view = views_get_view('references'); 
    $view->set_display('block'); 
    $output = $view->render(); 
    file_put_contents('references.html', $output); 
} 

function MODULE_NAME_node_update($node) { 
    unset($node->is_new); 
    unset($node->original); 
    entity_get_controller('node')->resetCache(array($node->nid)); 
    menu_execute_active_handler('outputview', FALSE); // or via curl 
} 

此作品爲視圖獲取正確呈現但仍使用與管理的主題。

hook_custom_theme

function MODULENAME_custom_theme(){ 
    return 'DEFAULT THEME HERE'; 
} 

回答

0

我找類似的東西。我發現了一些代碼(見修補程序#3 https://drupal.org/node/1813350),但它沒有幫助我們實現Shortcode contrib模塊。希望它對您有用或幫助您朝着正確的方向前進。

這是我們從補丁衍生嘗試:

$custom_theme_bu = drupal_static('menu_get_custom_theme'); 
$custom_theme = &drupal_static('menu_get_custom_theme'); 

$custom_theme = variable_get('theme_default', 'bartik'); 
unset($GLOBALS['theme']); 
drupal_theme_initialize(); 

$embed_view = views_embed_view('YOUR_VIEW_ID', 'YOUR_VIEW_DISPLAY_ID'); 

$custom_theme = $custom_theme_bu; 
unset($GLOBALS['theme']); 
drupal_theme_initialize(); 
+0

補丁實際工作。將兩個函數添加到您的代碼中,並調用第一個函數切換主題,然後在完成任務後調用第二個函數以恢復默認主題。我在cron電子郵件中使用它,它工作正常。 – sumanchalki