From http://drupal.org/node/1200012

Would it be possible to deny access to node creation forms also before the form gets filled in? Otherwise users get annoyed.

We have the same requirement. Not desperate but the change will improve the interface for our users.

Comments

Anonymous’s picture

As a workaround, you can use the Userpoints Role module (of the Userpoints contrib package). There you can create a role "userpoint owners" and then grant access to the creation form only for this specific role. Has up- and downsides, of course.

peterx’s picture

I will describe the current use case I am working on. There are others and hopefully other people will contribute their use cases.

We give the user a role when they purchase points and that controls access to the blocks/menus/views of data. They get the role on first purchase and keep the role when they get down to zero points. We need to stop creation when they are at zero but still give them everything else so they can see they are at zero.

We could use Userpoints Role to add an additional role if their points are greater than zero and give create access to the extra role. Installing the whole contrib package for one extra bit is a pain. We already have many roles defined and an extra one is a pain. If we can achieve the same with a few extra lines of code in an existing module, everything is easier including training the staff who will administer it.

I may look at rules for doing something similar to the Userpoints Role module but not today. I will have to leave research until next week.

The ideal would be to have the node add option visible and greyed out with a message about why it is greyed out. Another option would be to have the node add page visible and a big error message about no points with a link to the points purchase page.

BillyMG’s picture

Assigned: Unassigned » BillyMG
Status: Active » Needs review

This one is a bit tricky because of the way Drupal access controls work. It's much harder to disable access to something than it is to grant access. Because of this, and how every site could be different, it's not really in-scope of this module to do this functionality. However, I've created a function that may help in testing for this condition:

/**
 * Custom function to allow developers to manually check conditions before form execution
 * $account => A standard Drupal user object
 * $node_type => A node type to check against
 * $actions => An array of actions (machine name) that needs to be checked against
 * Returns 0 on an error, an empty array if everything is fine, and an array of invalid messages otherwise
 */
function userpoints_node_action_check_conditions($account, $node_type, $actions)

I would recommend you write a custom module that calls this function like so:

  global $user;
  $results = userpoints_node_action_check_conditions($user, "story", array("userpoints_node_created", "sticky"));
  if (empty($results)) {
    // Good to go
  } else {
    // They didn't have enough points
  }

This way you can do whatever you need to with the results. Please let me know if you have any questions regarding this, but hopefully it helps.

peterx’s picture

Thank you for the function. For the current project, the requirements simplified a bit, the range of purchase options was reduced, and I found a way to make things work. We will eventually go back to the original workflow because it is easier for some users with some purchases and we will then use your function.

BillyMG’s picture

Status: Needs review » Closed (works as designed)

Sounds good; let me know how it works out. I'll mark this as resolved for now.