Wednesday, January 11, 2012

Drupal custom status message on node submission

Drupal Content types are used for variety of features in a project. So when user submits a form, s/he gets a generic message "your "typename" has been created".

Best way to change these messages, and get a complete control over them is


function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  global $user;
  switch ($op) {
    case "view":
      global $_SESSION;
      if ($_SESSION['messages']['status']) {
          foreach ($_SESSION['messages']['status'] as &$value) {
            if (substr($value, -17) == 'has been created.') {
              switch ($node->type){
                case 'contact_us_website':
                  $value = "Contact Us form has been submitted. We have received your comments - Hawaii Savvy Team";
                  break;
                case 'report_problem':
                  $value = "Report problem form has been submitted. We have received your comments - Hawaii Savvy Team";
                  break;
                case 'event':
                  if(!(user_has_role('Administrator') || $user->uid==1))
                  $value = "Your Event has been submitted. We will publish it very soon  - Hawaii Savvy Team";
                  break;
              ....
......


For other ways look http://drupal.org/node/500202#comment-2210030

No comments: