2014-06-24 41 views
1

在貢獻模塊(ldap_sso.module)中正在聲明一個自定義drupal_set_message。Drupal 7未設置drupal_set_message

drupal_set_message(theme('ldap_authentication_message_not_authenticated', 
    array('message' => 
    t('You were not authenticated by the server. 
    You may log in with your credentials below.') 
) 
), 'error'); 

如何我可以覆蓋此消息或可能取消它通過我的自定義模塊,所以當LDAP SSO驗證失敗也不會被調用呢?

+0

難道這在settings.php配置來實現? $ conf ['locale_custom_strings_en'] ['您沒有通過服務器驗證。您可以使用下面的憑據登錄。'] ='錯誤被管理員刪除'; –

回答

1

如果您查看https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_set_message/7的drupal_set_message()的代碼,您將注意到僅當$ message參數不爲null時纔會設置消息。因此,如果我們以某種方式將$ message參數設置爲NULL,則不會設置任何消息。

幸運的是,由於LDAP模塊使用的是主題功能,這很容易。在正在使用的主題的template.php文件中定義主題函數。假設您使用的是一個名爲「mytheme」的主題。然後打開該文件夾中的template.php文件並添加以下代碼:

/** 
* Implements theme_ldap_authentication_message_not_authenticated(). 
*/ 
function mytheme_ldap_authentication_message_not_authenticated(&$vars) { 
    return NULL; 
} 

清除緩存。現在,主題('ldap_authentication_message_not_authenticated',...)將調用您定義的主題函數,而不是由LDAP模塊定義的主題函數。由於你的主題函數返回NULL,消息不會被設置。

Neerav梅塔

Drupal development in Bay Area

+0

謝謝。在自定義mytheme函數中,我不應該包括提取($ vars)嗎?或者是不知何故已經通過原來的ldap主題功能傳遞?我想可以這樣做:function mytheme_ldap_authentication_message_not_authenticated(&$ vars){ extract($ vars); $ message = NULL; 返回$ message; } –

+0

由於您根本不使用$ vars,因此不需要編寫「extract($ vars);」。 –