The conditions under the users obtain points vary a lot from site to site and are subject to very specific conditions. So earning / losing points as a result of an event should now be done with rules, IMHO. Provide some basic rules examples could be useful to site builders. As far I can see, the top 5 most common actions are:

  • user login
  • user register
  • add some content
  • edit/review some content
  • post a comment

Comments

manuel.adan created an issue. See original summary.

manuel.adan’s picture

Status: Active » Needs review
StatusFileSize
new46.69 KB
new14.09 KB

A new sub-module with example rules has been added. The example reaction rules provided by it are:

  • user login: 5 points
  • user register: 10 points
  • add some content: 5 points
  • edit/review some content: 10 points
  • post a comment: 20 points

User points rules example screenshot

Someone else is needed to test it before committing!

Please, to do so:

  1. download all the required modules: userpoints (latest -dev), typed_data (alpha1), rules (alpha3), dynamic_entity_reference (latest stable), transaction (alpha3)
  2. new rule actions are needed to create and execute transactions, apply this two (not-yet committed) patches to the transaction module: #2958236-3: Add execute transaction rule action & #2958093-3: Add create transaction rule action
  3. apply the attached patch to the userpoints module
  4. enable the new sub-module "User points rules example" (userpoints_rules) provided by this patch
  5. rebuild caches from drush, and again from the UI (/admin/config/development/performance) because of this rules bug: #2957985: Reaction rules not triggered after cache rebuild from drush
  6. try it doing any of the actions described above

You can edit the provided rules, for example, adding conditions to them or changing the amount of points granted, but note that provided rules (updated or not) are removed if the userpoints_rules sub-module is uninstalled.

socialnicheguru’s picture

Status: Needs review » Needs work

Here is the error I get on login as user 1

https://test1.com/user/login|1||Drupal\rules\Exception\EvaluationException: The context for transaction is NULL, but the context transaction in transaction_execute requires a value. in Drupal\rules\Plugin\RulesExpression\RulesAction->prepareContext() (line 98 of rupal-8.5.1/html/modules/contrib/rules/src/Context/ContextHandlerTrait.php).

socialnicheguru’s picture

I goto my user/1 page
I click on a subtab and get the following:
a WSOD and in my logs:
TypeError: Argument 1 passed to Drupal\transaction\Entity\TransactionType::isApplicable() must implement interface Drupal\Core\Entity\ContentEntityInterface, string given, called in drupal-8.5.1/html/modules/download/transaction/src/Access/ApplicableTransactionAccess.php on line 112 in Drupal\transaction\Entity\TransactionType->isApplicable() (line 235 of drupal-8.5.1/html/modules/download/transaction/src/Entity/TransactionType.php)

manuel.adan’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hi SocialNicheGuru, thank you so much for your feedback on this.

I have been trying to reproduce the errors you reported, but I was unable to do it starting from a fresh Drupal 8.5.1 installation (standard profile). However, I found that the configured actions in the provided rules can not be edited, I got a 404 in URLs like:

/admin/config/workflow/rules/reactions/edit/userpoints_rules_earn_on_login/edit/

This doesn't affect to the rule application, I mean, users grant points on login or posting as expected, but it could be related with the errors you got.

About the first one:

https://test1.com/user/login|1||Drupal\rules\Exception\EvaluationException: The context for transaction is NULL, but the context transaction in transaction_execute requires a value.

here the execution action found an empty transaction context. The transaction entity should be created by the previous action, but it doesn't. It appears that, for some reason, it is not possible to create new user points transactions in your system with the default type. Did you alter (or delete) the default transaction type and fields provided by the userpoints_default module?

I need some other information in order to reproduce it:

- drupal version
- php version
- required modules version: typed_data, rules, dynamic_entity_reference & transaction
- full log entries on error

socialnicheguru’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

I recreated the site and it all seems to work just fine.

I don't know what it was.

It actually seems to be working just fine.

socialnicheguru’s picture

I am not sure if it is my setup for module but when I click on the reaction of any of the rules added here, I get a page not found

manuel.adan’s picture

Status: Reviewed & tested by the community » Needs work

When trying to reproduce the issue described in #4, I noticed the same:

I found that the configured actions in the provided rules can not be edited, I got a 404 in URLs like:

/admin/config/workflow/rules/reactions/edit/userpoints_rules_earn_on_login/edit/

By adding some additional reaction, the existing one can be edited normally. it might be a rules issue, but I have to see it.

manuel.adan’s picture

As far I can see, rules stores in a single config entity the entire rule. This config entity has an UUID as usual that must be removed from the default configuration provided in userpoints_rules. However, each rule expression has also its own UUID that, unlike the entity UUID, it should be present in configuration.

By design, UUIDs are machine-generated identifiers that shouldn't be stored in any component code or default configuration. I opened an issue about this in the rules module queue, #2964770: Cannot edit reactions of imported rules from module config install

In the mean time, and considering that the purpose of the new submodule is to illustrate the rules integration, I added UUIDs values to provided rules expressions. With this change, the rule action edit links work.

socialnicheguru’s picture

I can now go and edit a rule

edit: admin/config/workflow/rules/reactions/edit/userpoints_rules_earn_on_content_post/edit/12126733-fa8e-4f1f-bca5-5729acbc8f11
which is
Home Administration Configuration Workflow Rules Edit reaction rule "Earn points for content added"

I only goto the bottom of the page and hit save, and I get this error:

Expected a entity data type for context Target entity but got a entity_reference data type instead.

manuel.adan’s picture

That's another rules issue. Such context selection is valid, validation works when creating new action but fails on edition. Issue post in rules: #2965726: Entity context fields fails on validation on update for entity reference

As a work around, the only affected reaction fetch first the user node author and uses this reference for the target entity context in the transaction creation rule.

Note that rules also requires to rebuild the cache after updating a rule to be applied.

manuel.adan’s picture

Added actions to set a reference to the reaction related entity. It can be tested with the latest -dev of the transaction module + patch from #2973989-2: Transaction type context refination in rules doesn't work.

socialnicheguru’s picture

Do you check to see if the userpoints can be applied to the content type ie. if field_userpoints_default_linkref is present?

I had this error come up automatically on save of a content type.

Here is the issue description
Unable to apply data selector '' at 'field_userpoints_default_linkref'

ohmdesbois’s picture

Hello,
I tried to install the transaction dev version (with the transaction-transaction_type_rules_context_refination-2973989-2.patch patch) and the userpoints dev version (with the https://www.drupal.org/files/issues/2018-05-19/userpoints-basic_rules_examples-2956286-12.patchpatch), but I can't enable userpoints_rules because

Transaction (Version> = 8.x-1.0-alpha2 required)
User points default requires this module and this version. You are currently using Transaction version

I hope this can help.
Thank you

socialnicheguru’s picture

I have problems with the field_userpoints_default_linkref field. (I closed the issue to just add it to this one since this patch is causing the problem).

on the DER page for the field_userpoints_default_linkref several of the fields have required values that are not filled in. Some have required values but no options available. (See the attached files).

I get the following errors:
http://mysite.com/node/add/my_polls|1||Drupal\typed_data\Exception\InvalidArgumentException: Unable to apply data selector 'field_userpoints_default_linkref' at 'field_userpoints_default_linkref':

Field field_userpoints_default_linkref is unknown. in Drupal\typed_data\DataFetcher->fetchDataBySubPaths() (line 100 of drupal-8.5.3/html/modules/contrib/typed_data/src/DataFetcher.php

Process:
I have enabled userpoints_default
I applied the userpoints_rules patch
I enabled userpoints_rules
I created a content type called poll with an entity reference to the poll entity (http://drupal.org/project/poll).
I hit save and got a white screen
I had to refresh my screen and the content type was saved but I do not think the userpoint was

I then went to the transaction type:
admin/config/workflow/transaction/edit/userpoints_default_points/fields/transaction.userpoints_default_points.field_userpoints_default_linkref

and I noticed that I had to select content types under the dynamic field options.

Some have no options available but still are required (redhen)

socialnicheguru’s picture

If you use DER what happens once there is content in the system? I don't think you can modify this field at all.

Would a better approach be to modify the rule and only allow certain entities to execute it that way you don't have to worry about changing the DER field later?

manuel.adan’s picture

Assigned: Unassigned » manuel.adan
Category: Plan » Task
Related issues: +#3022258: Link field reference has incomplete configuration

The reported issues in #15 and #16 seems to be caused by incomplete configuration in the link field provided by userpoints_default sub-module. Since it is not related to rules examples, I've opened a new issue for that: #3022258: Link field reference has incomplete configuration. Thank's @SocialNicheGuru for the feedback!

We are on the way of a first alpha release, latest patch needs be updated to accommodate to changes in the main module.

manuel.adan’s picture

Assigned: manuel.adan » Unassigned
Status: Needs work » Needs review
StatusFileSize
new17.04 KB
new29.15 KB

Updated patch with 3 changes:

  • the sub-module name changes from userpoints_rules to userpoints_rules_example, that matches much better its purpose. In the D7 version already exists a userpoints_rules sub-module that provides integration with rules (not required in the D8 way), and might cause some confusion
  • the sub-module is now located in the new modules folder, according to #3022279: Move sub-modules to modules folder
  • added dependency on node (core) and token modules. Entity reference fields tokens are provided by the contrib token module

There are no changes in the provided configuration examples.

socialnicheguru’s picture

userpoints_defaults is a requirement which also means that 'Article" type is needed.

manuel.adan’s picture

Assigned: Unassigned » manuel.adan
Status: Needs review » Needs work

Default submodule is intended to be used as a starting point for almost any website. Dependency on node or comment is not really required, so I opened an issue to remove it: #3024998: Remove dependencies on node and comment modules in userpoints_default.

In rules example, we have now to ensure that the link entity reference field allows references to content and comment entities.

manuel.adan’s picture

Assigned: manuel.adan » Unassigned
Status: Needs work » Needs review
StatusFileSize
new18.1 KB
new945 bytes
manuel.adan’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new18.83 KB
new643 bytes

Transaction 1.0-alpha4 released that provides the required rules integration. No other changes or issues reported, ready to commit.

  • manuel.adan committed 1fdd568 on 8.x-1.x
    Issue #2956286 by manuel.adan, SocialNicheGuru: Add basic rules examples
    
manuel.adan’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.