Pages

Showing posts with label node. Show all posts
Showing posts with label node. Show all posts

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

Tuesday, June 28, 2011

Drupal | programmatically create node with file field

$node = new StdClass();
        $node->type = 'bzl_img';
        $node->uid = $_GET['user_id'];
        $node->field_bzl_img_ref[0]['nid']=$_GET['bz_id'];
        $node->status = 0;
        $node->field_bzl_img_main[0]['value']=0;