Community Documentation

Display a custom message with the Node_limitnumber module.

Last updated November 7, 2009. Created by jpbaldiga on November 7, 2009.
Log in to edit this page.

I wanted to restrict the the number of posts a Certain Role could create. So I installed the "node_limitnumber" module.

It worked out great, except I was wanting a bit more functionality when it came to the execution of the code.

As the module is now, if a user try's to create more than their allowed the, module re-directs them to the add content page and following error message is displayed...

"You can't create more content of type !type, sorry."

Effective... But I decided to add some "snippets" to the node_limitnumber.module file for configuring conditional messages. This was my first real php programming venture.

Before.. (starting at line 152 of node_limitnumber.module,v 1.6.2.1 2009/09/22)

$result = db_query( $q, $node->type, $user->uid);
      $num = db_affected_rows();
      if ($num >= $limit) {// We have the data, now we check the limit
        $nodetypename = node_get_types('name', $node);
        drupal_set_message(t("You can't create more content of type !type, sorry.", array('!type' => $nodetypename)), 'error');
        drupal_goto('node/add');
      }
    }
  }
}

And After...

$result = db_query( $q, $node->type, $user->uid);
      $num = db_affected_rows();
      if ($num >= $limit) {// We have the data, now we check the limit
        $nodetypename = node_get_types('name', $node);
        switch ($nodetypename)
{
case "Story":
        drupal_set_message(t("We're sorry, Standard accounts are limited to 3 New Story posts a week.", array('!type' => $nodetypename)), 'error');
        drupal_goto('node/add');
  break;
case "Page":
        drupal_set_message(t("We're sorry, But you're only allowed one user page. If you feel you've reached this message in error, please contact us.", array('!type' => $nodetypename)), 'error');
        drupal_goto('node/add');
  break;
default:
        drupal_set_message(t("It seems you already have a !type... It may be a technical issue though. Try again, and if you still have trouble <a href='/support'>click here</a> to contact customer support.", array('!type' => $nodetypename)), 'error');
        drupal_goto('node/add');
}
      }
    }
  }
}

Oh yeah... You can also make the redirect conditional where you see drupal_goto(''node/add");

Hopefully some of you find this useful, that and it inspires someone with mad php Skills to further develop this module.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders, Documentation contributors, Site users

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.