簡體   English   中英

改變Drupal 7中的消息

[英]Alter messages in Drupal 7

drupal中有幾條消息。 當出現php警告時,會引發錯誤消息,但模塊也可以使用drupal_set_message()引發消息。 問題是:有沒有辦法改變這些消息? 例如,在每條消息中用'b'替換每個'a'。

謝謝!

雖然set上沒有消息更改,但您可以通過hook_preprocess_status_messages更改它們,請參閱http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/7預處理和http: //api.drupal.org/api/drupal/includes--theme.inc/function/theme_status_messages/7

編輯:你也可以嘗試字符串覆蓋檢查http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/t/7 ,簡而言之$conf['locale_custom_strings_en']['some message'] = 'some messbge'; 對於英語,如果它不是英語,請更改_en以獲取其他內容。

字符串覆蓋是最好的解決方案,但是

  • 如果你試圖在消息中覆蓋的東西是變量OR
  • 您想要替換所有消息中的字符串

然后字符串覆蓋無法幫助你,這是一個解決方案。

hook_preprocess_status_messages()傳入$ variables但消息不在$ variables中,在$ _SESSION ['messages']中更改它們。

/**
 * Implements hook_preprocess_status_messages()
 */
function MYMODULE_preprocess_status_messages(&$variables) {
  if (isset($_SESSION['messages']['warning'])) {
    foreach ($_SESSION['messages']['warning'] as $key => $msg) {
      if (strpos($msg, 'some text in the message') !== FALSE) {
        $_SESSION['messages']['warning'][$key] = t(
          'Your new message with a <a href="@link">link</a>.',
          array('@link' => url('admin/something'))
        );
      }
    }
  }
}

感謝Parvind Sharma ,我發現了這個解決方案的一部分。

String Overrides模塊不允許您在字符串中替換A和B,但它允許您替換整個字符串(drupal 6和7) http://drupal.org/project/stringoverrides

但是,如果您更喜歡使用自己的代碼段,那么我就是這樣做的。

在mymodule.install中

function mymodule_update_7001() {
$custom_strings = array(
    ''=>array(//context is blank
        'Old string' => '', //blanking the string hides it
        'Another old string.' => 'New String'
    )
);

variable_set("locale_custom_strings_en",$custom_strings);   //note, this is only for english language
}

然后運行update.php以進行更改

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM