I want to hide error and warning message from admin panel. I have checked the option None in admin panel for error reporting and still it showing error and warning messages in admin panel. let me how it can removed.
4 Answers
The code suggested by indrock would remove all the messages shown by the modules, not just error messages, and warnings.
What you can do is implement THEME_preprocess_HOOK()
using the following code.
function mytheme_preprocess_page(&$variables) {
if (path_is_admin(current_path())) {
unset($_SESSION['messages']['warning']);
unset($_SESSION['messages']['error']);
}
}
current_path() currently returns the value of $_GET['q']
; I am using it for compatibility with Drupal 8, as for that version current_path() is not simply returning the value of $_GET['q']
.
Instead of unset($_SESSION['messages'][$type])
, you can use drupal_get_messages($type, TRUE)
. Using drupal_get_messages()
, you are sure your code works even when the messages are stored in a different session variable, or a variable that is a session variable. So far, it doesn't seem necessary, as Drupal 8 uses the same session variables used from Drupal 7, for the messages.
The settings in admin/config/development/logging are for error messages caused by PHP code. They don't influence the error messages shown by modules.
-
this gives more control on the type of messages. A better solution ;-)– AjitSCommented Sep 23, 2012 at 14:59
Although it is not a good idea to hide the errors (you may want to solve it; by watching the error log, debugging etc.), there is a way you can do it.
You can do it at theme level in template_process_page()
function, in your theme's template.php file. (It should be placed in your admin theme's template.php)
Code: Edited according to @Chapabu 's comments :)
Used path_is_admin()
and current_path()
.
<?php
function MYTHEME_process_page(&$variables) {
if (path_is_admin(current_path())) {
unset($variables['messages']);
}
}
?>
-
i think it will unset this for whole site while i want it only for admin panel Commented Sep 11, 2012 at 8:53
-
-
I have tried the way you mention but it still showing errors on admin panel configuration as shown in the screenshot in question...plz have a look Commented Sep 11, 2012 at 9:17
-
1Don't forget you'll need to put this code in the template.php for the admin theme, not the for your site theme!– ChapabuCommented Sep 11, 2012 at 11:07
-
1Also, I'd replace
if (arg(0) == 'admin')
withif (path_is_admin(current_path()))
just in case you're on an admin page that doesn't start withadmin
(such as the feed importer page)– ChapabuCommented Sep 11, 2012 at 11:10
To hide Error and Warnings using Admin panel goto
admin/config/development/logging
Select None to hide errors.
-
I have tried this it did not work for me....:( Commented Sep 11, 2012 at 11:38
You can only make it so that the error shows on certain usernames, because sometimes they do give out helpful information like "Module Update reminder" etc.
function MYTHEME_process_page(&$variables) {
global $user;
if (path_is_admin(current_path()) == TRUE) {
if(!in_array($user->name,array('username1','username2'))) {
$variables['show_messages'] = FALSE;
}
}
You can replace/add to array username1 and username2 with whatever usernames you would wish to show the error messages to.