Change messages in Drupal 7

There are several posts in drupal. When the php warning appears, an error message appears, but the module can also raise messages using drupal_set_message (). Question: is there a way to change these messages? For example, to replace each "a" with "b" in each message.

Thank!

+3
source share
3 answers

While there is no change specified, you can change them on the display via hook_preprocess_status_messages, see http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/7 in the preprocess and 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 - .

+7

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

0

" " - ,

  • , , OR

, .

hook_preprocess_status_messages () passes in $ variables, but messages are not in $ variables, change them in $ _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'))
        );
      }
    }
  }
}

Credit Parvind Sharma , where I found part of this solution.

0
source

Source: https://habr.com/ru/post/1790897/


All Articles