Drupal Theme Error Messages
Contents |
theme.inc theme_status_messages() 4.7.x theme.inc drupal error messages not showing theme_status_messages() 5.x theme.inc theme_status_messages($display = NULL) 6.x theme.inc
Drupal Webform Error Messages
theme_status_messages( to display status messages Closed (fixed)Project:Style GuideVersion:7.x-1.x-devComponent:CodePriority:NormalCategory:Bug reportAssigned:UnassignedReporter:mstrelanCreated:March 17, 2011 - 00:40Updated:May 30, 2015 - 23:14 Log https://api.drupal.org/api/drupal/includes!theme.inc/function/theme_status_messages/7.x in or register to update this issue Jump to:Most recent comment Most recent attachment Here is a patch against 6.x-1.x-dev which uses the correct theme function while not messing up the existing message queue. You can https://www.drupal.org/node/1095436 test it by adding the following. Sorry it is not against 7.x as I haven't had a chance to look if status messages are handled the same way.Files: CommentFileSizeAuthor #14 Screen Shot 2015-05-16 at 3.53.42 PM.png46.78 KBdead_arm #13 styleguide-use-theme-status-messages-1095436-13.patch1.25 KBdead_arm PASSED: [[SimpleTest]]: [MySQL] 154 pass(es). View #7 Screenshot_2013-05-10_12_04_AM.png18.43 KBZach Harkey #7 Screenshot_2013-05-10_12_01_AM-3.png19.83 KBZach Harkey #5 styleguide_use-theme-status-messages-to-display-status-messages-7.x-1095436-4.patch1.26 KBlogaritmisk PASSED: [[SimpleTest]]: [MySQL] 154 pass(es). View #1 styleguide_use-theme-status-messages-to-display-status-messages-2.patch1.51 KBmstrelan FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch styleguide_use-theme-status-messages-to-display-status-messages-2.patch. Unable to apply patch. See the log in the details link for more information. View styleguide_use-theme-status-messages-to-display-status-messages.patch1.53 KBmstrelan FAILED: here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more http://drupal.stackexchange.com/questions/14832/print-messages-in-node-tpl-php-file about hiring developers or posting ads with us Drupal Answers Questions Tags Users Badges Unanswered Ask Question _ Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute: http://tylerfrankenstein.com/user/4/code/hook-preprocess-drupal-messages Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Print $Messages in node.tpl.php file up vote 19 down vote favorite 11 In error message Drupal 7, by default the $messages variable is printed in page.tpl.php. Is there a way to print $messages in a node.tpl.php file (e.g. $node-mycontenttype.tpl.php). Just putting or does not work. There's a tutorial here for printing $messages in a block, but I would like to put it in my node.tpl.php file. theming share|improve this question asked Nov 5 '11 at 16:10 big_smile 62732763 I think theme_status_messages is drupal error message being called before template_preprocess_node so drupal_get_messages is empty when you call it. –anonym-developer Nov 18 '11 at 0:14 add a comment| 2 Answers 2 active oldest votes up vote 29 down vote accepted Actually, what you want to do is this: function YOURTHEME_preprocess_page(&$variables) { // This disables message-printing on ALL page displays $variables['show_messages'] = FALSE; } function YOURTHEME_preprocess_node(&$variables) { $variables['messages'] = theme('status_messages'); } How this works: Drupal core checks the value of show_messages in theme_process_page. If it is TRUE (default) then it calls theme('status_messages') as above, and effectively empties the messages storage, so calling the same theme function later will just return an empty string. However, if we set that variable to FALSE, this prevents said theme function from being called in process_page, allowing us to get all the messages using the same theme function, in a template of our choosing. share|improve this answer answered Jan 16 '13 at 12:37 Freek 40544 1 And if you only want this to take action on node pages, just wrap the $variables['show_message'] = FALSE with a conditional to see if(isset($variables['node'])). –areynolds Jan 18 '13 at 0:55 And you have to do the same for all other pages (views, panels, etc) –Maria Ioannidou Jul 21 at 14:46 add a comment| up vote 8 down vote The answer in How to display messages from a block separately from $messages in page.tpl.p Messages Hook into and Preprocess Drupal Messages Submitted by tyler on Fri, 05/20/2011 - 11:11 Updated: 2013-04-02 Category:CodeTags:drupal 6.xplanet drupal So after the line dancing party at the pole barn in Corn County last night, I needed to prevent/hide Drupal messages from being displayed to certain user roles under certain conditions. Luckily Betty Sue, from Corn City, told me about theme_status_messages().After copying theme_status_messages() into my theme's template.php file and renaming the function to mytheme_status_messages, I was ready to rock.The following example hides all error/warning messages from anonymous users and user's who don't have the 'administer nodes' permission. You can easily add your own conditions to filter out which message types should be displayed to who. function mytheme_status_messages ($display = NULL) { $output = ''; foreach (drupal_get_messages($display) as $type => $messages) { // skip all error/warning messages for anonymous users if (!user_is_logged_in() && ($type == "error" || $type == "warning")) { continue; } // skip error/warning messages for users who don't have the 'administer nodes' permission else if (!user_access('administer nodes') && ($type == "error" || $type == "warning")) { continue; } ... Technically we aren't hooking in or preprocessing anything by Drupal definitions, we are actually themeing the messages the way we want, but I figured I'd include those keywords to help people get here and learn the goodness.Don't forget to flush the theme registry and wash your hands when you're done.Update: 2011-06-22 - I came across the module Disable Messages which appears to have a UI to do similar tasks. Haven't tried it out yet, but it has 6.x and 7.x versions, and is under active development. Rootin' tootin'! Comments Anonymous (not verified) Tue, 11/15/2011 - 04:24 Permalink Thanks! You'r post helped me Thanks! You'r post helped me to find solution of this problem: http://drupal.org/node/1043808#comment-5245710 reply Interdurper (not verified) Tue, 09/30/2014 - 07:26 Permalink Thanks for the tip! Thanks for the tip! Just an update for D7: $display = NULL) 7.x theme.inc theme_status_messages($variables) Returns HTML for status and/or error messages, grouped by type. An drupal hide error messages invisible heading identifies the messages for assistive technology. Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html for info. Parameters $variables: An associative array containing: display: (optional) Set to 'status' or 'error' to display only messages drupal hide error messages from users of that type. Related topics Default theme implementations Functions and templates for the user interface to be implemented by themes. 5 theme calls to theme_status_messages() ajax_prepare_response in includes/ajax.inc Converts the return value of a page callback into an Ajax commands array. file_ajax_upload in modules/file/file.module Menu callback; Shared Ajax callback for file uploads and deletions. hook_ajax_render_alter in modules/system/system.api.php Alter the commands that are sent to the user through the Ajax framework. template_preprocess_maintenance_page in includes/theme.inc Process variables for maintenance-page.tpl.php. template_process_page in includes/theme.inc Process variables for page.tpl.php File includes/theme.inc, line 1673 The theme system, which controls the output of Drupal. Code function Drupal Error Message The File Could Not Be Created function MYTHEME_status_messages ($variables) { $output = ''; // skip all error/warning messages for anonymous users if (!user_is_logged_in() && ($type != 'status')) { return $output; } // default processing else { return theme_status_messages($variables); }}
reply Add new comment Y