Hello,
Still a bit new to Rules, but I have been looking around and checking the documentation and API for the solution to my problem; still, I am quite lost as to where to begin, how to proceed.
So, all I want is to restrict, for a particular user role, the creation of nodes of a particular content type, by a quota. I want to count how many nodes of that type the user currently has. And say, that the maximum amount allowed for that user is 5, and he/she already has 5 nodes of that type when he/she tries to create a new one, negate the creation of the node.
How can I achieve this? There used to be a Create Quota (http://drupal.org/project/create_quota) module, but it was discontinued, so I'm assuming this is possible with just rules?
Help will be greatly appreciated. Thanks.
Comments
Node Limit Module
Check this out: http://drupal.org/project/node_limit
Jason.
Is there not a way to achieve
Is there not a way to achieve this with Rules? I'd like to avoid having to install so many modules, so if I can do it with one I already have installed, that'd be ideal. Also, I am in Drupal 7. How stable is this module in D7?
Thanks!
Page manager access
Maybe you're using page manager already? You could do this with page manager, setting the access attribute to evaluate a rules condition component.
I think this will give you the essential part
http://vimeo.com/30536918
Hope this helps.
This approach is very
This approach is very interesting. My only question right now is, do I actually need to create a view? Because I would only use that view for the logic in my custom rule; I wouldn't be using it in any other way. Well... I can still work something out; maybe I'll use the view in the end, maybe not. Either way, I think I'll give this a shot.
I'll come back to share the results, be they successful or not. :)
Thanks!
I'm seeing the person in the
I'm seeing the person in the tutorial do something with Views. Do I actually need to create a view for this to work? Sorry for being so picky; I just want to find the most efficient way to do this. I can program in PHP, it's just that I am new to the Drupal API and I find it so complex. I first considered whether I had to create a custom condition or something like that, but that's the thing: I'm not sure if that's what I need.
If only I could get the number of nodes of a specific content type, created by the user in question, and make a comparison, I know how to handle the rest.
I know the feeling.
Rules out of the box supports views and flags as listing service. Views without a page, as in the video example, is using it as an easy way to the database. (Your view can be exported, so that you still have everything in code, to move around in deployment scenarios.)
If you don't want the views dependency, (quite reasonable) then rules also provides a pluggable architecture, so you could implement your own condition (a database query that got your node count without depending on views), and then expose it to views.
Do you know any good
Do you know any good tutorials to the Rules API, to learn how to implement a custom condition? What I've found in the documentation seems to assume or expect that I am already fluent in the Drupal API. The Drupal API seems to have so many layers of abstraction; it's hard to tell what I'm looking at.
Coding Rules
There are a lot of layers to the onion, some are very sweet, some are not clean as they might be.
The episode I linked above was #25 of 32 on using rules as site-builder, and it is very well structured, and you can actually build the examples as he does, it does work.
Following from there is a shorter series on coding rules plugins, and I guess it would be episode 6 that would be the sweet sort for you.
http://dev.nodeone.se/en/coding-for-rules-2
Thanks!
I decided to just code my own conditions, and the condition is working properly so far. However, there is one optional parameter I would like to add to my condition; basically, I'd like to let the user specify the content types he/she would like to restrict, if any. So, my condition function is as follow:
<?php/**
* Implementation of hook_rules_condition_info().
*/
function nodecount_rules_condition_info() {
$conditions = array();
$conditions['nodecount_rules_condition'] = array(
'group' => t('Nodes'),
'label' => t('User has reached their active (published) node quota'),
'parameter' => array(
'node' => array(
'type' => 'node',
'label' => t('Node being created or changed')
),
'quota' => array(
'type' => 'integer',
'label' => t('Specified quota')
),
'c_type' => array(
'type' => array(
'text',
'list<text>',
'token',
'list<token>'
),
'label' => t('Specified content type (optional)'),
'optional' => TRUE,
'allow null' => TRUE,
'default mode' => 'selector'
)
),
'module' => 'nodecount',
);
return $conditions;
}
?>
The third parameter (c_type) is the one I have problems with. Rules is still forcing me to add values to it, even though I explicitly indicated that it is to be an OPTIONAL parameter. Furthermore, I want the default mode to be selector rather than input, but I'm still seeing input by default. I also tried the allow null option. Neither of those three options seem to have any effect, though. Is the API documentation outdated, or am I doing something wrong?
Here is a screenshot, for reference:
Maybe I should raise this question independently from the others in a new discussion, but I'm not sure. If you can point me in the right direction, I'd be so grateful.
Thanks!