5

I used Rules module to know when a user has logged in and notify the user about his/her login event.

Now I just want to check when the user has submitted a content of one specific type for the first time, so I just can understand when the user has submitted his/her first content of a speccific content type!

How can I modify my rule in Rules to implement this?

3 Answers 3

4

While given answer works great, there are usually a variety of different methods to achieve your goals, one solution could be usage of a combination of Views and Views Bulk Operations (VBO) modules to achieve that

  • Create a view containing nodes of your desired type
  • Add a contextual filter and limits results to nodes written by logged in user
  • add a VBO view mode
  • in rules you can load a VBO items (check how)
  • Now if array is empty, created node is the first node of that type which the user has submitted

You also might do all the job with Rules, if you don't want this feature for many content types you can add a Boolean field to the user's account with default value of 'False' indicating if user has written his/her first content of desired type, then on node submit event you can check this field to recognize if this post is his/her first post of that type or not. Remember to set this field to True after submission of first content of desired type.

The above approach saves some processing cause needs no query as it calculated once and used many times

You also can write a custom rules event (API), containing a query on nodes table with condition node.uid == user->uid and node.type == "TYPE_MACHINE_NAME", then if query is not empty, that means user has already submitted a content of that type. so return False.

4

Another solution, which does not require ANY additional modules, is to create a dedicated role, let's call that role "Contributor" (use whatever role fits).

Then create a rather basic rule like so:

  • Rules Event: After saving new content.
  • Rules Conditions (both must be satisfied):
    • The submitted content has a type that matches your specific type.
    • The current user does NOT yet have role "Contributor".
  • Rules Action = Assign the "Contributor" role to the author of the node.

With the above in place, improve your existing rule to check if ... you guessed it ... the user has role "Contributor".

3

Use the Flag module to flag a user when they first submitted content that fits your requirements. To flag such user create a rather basic rule like so:

  • Rules Event: After saving new content.
  • Rules Condition: Whatever fits (if any).
  • Rules Action = Flag the user.

With the above in place, improve your existing rule to check if the user is flagged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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