3

I am interested in limiting the nodes a user can publish.So Node limit module cannot help on this. Someone suggested using userpoints and rules to achieve this. How is this possible with these 2 modules? Any help would be appreciated. thanks!

2

Give a try to User Points Contributed module: This module includes the module called userpoints_nodelimit which enables a limit on node creation based on user points.


However if you want to do it with the userpoints and rules module than the idea would be to create the rule to grant certain point on publishing the new nodes, and than create another rule whose event would be the node creation and in the condition check if the user already has reached limit than prevent node creation and display the custom message.


Alternatively one easy way to achieve the same is using the hook_node_validate(), one example of using the same is as below:

/**
 * Implements hook_node_validate().
 */
function MyModule_node_validate($node, $form, &$form_state) {
  // For now assign the static value to MAX_NODES (No. of nodes),
  // however you can make it dynamic, and get those values using variable_get().
  $max_nodes = 'MAX_NODES';
  $node_count = 0;

  // Get the user uid from the global user variable.
  global $user;
  $user_id = $user->uid;

  if ((isset($node->uid))) {
    // Use entity query to get the number of nodes already published by this user.
    $query = new EntityFieldQuery;
    $node_count = $query->entityCondition('entity_type', 'node')
      ->propertyCondition('uid', $user_id)
      ->propertyCondition('status', 1)
      ->count()
      ->execute();

    // Check if the node count exceeds the max_node value.
    if ($node_count > $max_nodes) {
      form_set_error('FIELD_NAME', t('Reached the maximum limit of creation of nodes.'));
    }
  }
}
  • I cannot make this work,is this possible you export the rules and pastes them here? – sokratis Oct 20 '13 at 16:54
  • @sokratis I will try that, but meanwhile can you try the alternate method I have added in my answer just now. – Ankit Agrawal Oct 20 '13 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.