Rules module

Hi Juan,

Do you mean you opened a ticket? I don’t think admins will have a look at it because this module doesn’t have a stable version yet.

I visited your website today and there were no rules created in order to understand what you were trying to do.

If your second rule was similar to the first one. For example a different action for the same conditions as for the same rule then it make sense that it failed. If you want the same conditions but different acctions you need to create one rule and have them all there.

Also, everytime you create a rule and save it you need to clear caches. I ran into a similar problem with a rule not running because I haven’t cleared caches.

This is what i tried to do:
image
I have a logical OR comparison(multiple comparison status pipeline) in order to check the value of two fields. If the condition is met, then it calls the action set ‘set field value to 1’.

The action set ‘set field value to 1’ just calls the action ‘set to 1’

This works fine. Problem comes when I try to create a second rule like this.
First I create a simple action called ‘set to 2’. Then, if I create a second action set ‘as set field value to 2’, even before creating a second rule or comparison, it just doesn’t show the previously created action ‘set to 2’

I attach the error:

So this rule should run after the first rule? Are they related to each other?

No, they should be independent. They just check some fields in the form in order to set the field ‘status’

Ok please write to me the settings and values of both rules so I can try them myself.

Maybe is better that I send you 2 of the original rules in Drupal 7:

{ “rules_set_in_preparation” : {
“LABEL” : “Set In Preparation”,
“PLUGIN” : “reaction rule”,
“WEIGHT” : “5”,
“OWNER” : “rules”,
“TAGS” : [ “conditions”, “status” ],
“REQUIRES” : [ “rules” ],
“ON” : { “node_presave–cv_project_new_template” : { “bundle” : “cv_project_new_template” } },
“IF” : [
{ “OR” : [
{ “data_is” : { “data” : [ “node:field-cv-cl-start-” ], “value” : “2” } },
{ “data_is” : { “data” : [ “node:field-cv-cl-start-” ], “value” : “1” } }
]
},
{ “NOT AND” : [
{ “data_is” : { “data” : [ “node:field-en-ice-start-design-and-co” ], “value” : “2” } }
]
}
],
“DO” : [
{ “data_set” : { “data” : [ “node:field-conditional-status” ], “value” : “2” } },
{ “drupal_message” : { “message” : “The Status of the project [node:title] was set as IN PREPARATION” } }
]
}
}

{ “rules_set_development” : {
“LABEL” : “Set Development”,
“PLUGIN” : “reaction rule”,
“WEIGHT” : “4”,
“OWNER” : “rules”,
“TAGS” : [ “conditions”, “status” ],
“REQUIRES” : [ “rules” ],
“ON” : { “node_presave–cv_project_new_template” : { “bundle” : “cv_project_new_template” } },
“IF” : [
{ “data_is” : { “data” : [ “node:field-cv-cl-start-” ], “value” : “2” } },
{ “data_is” : { “data” : [ “node:field-en-ice-start-design-and-co” ], “value” : “2” } },
{ “NOT OR” : [
{ “data_is” : { “data” : [ “node:field-i-o-tests-in-situ-by-cv-cl” ], “value” : “2” } },
{ “data_is” : { “data” : [ “node:field-i-o-tests-in-situ-by-cv-cl” ], “value” : “1” } },
{ “data_is” : { “data” : [ “node:field-i-o-tests-in-situ-by-cv-cl” ], “value” : “3” } }
]
}
],
“DO” : [
{ “data_set” : { “data” : [ “node:field-conditional-status” ], “value” : “3” } },
{ “drupal_message” : { “message” : “The Status of the project [node:title] was set as DEVELOPMENT” } }
]
}
}

If you see the form, the field status (it is normally a hidden field), takes its value depending on other fields in the form (data gathering, specification, …)

This could be implemented probably using some js and DOM but I’d prefer to use a predefined module.

Thanks

Hi Juan,

I can’t find the content type cv_project_new_template on your Drupal 8 website https://test-en-dep-cv-cl-v2.web.cern.ch

Hi Sotirios,

Content type name for cv_project_new_template is EN-CV Project.
https://test-en-dep-cv-cl-v2.web.cern.ch/admin/structure/types/manage/cv_project_new_template/fields

Also from main menu, ‘CV-CL Project Status’, you can click on any of the projects title links. Then, click edit and there it is the form for a single project.


Thanks,
Juan

Hi Juan,

I tried different options, tried some patches for the error but nothing seems to work. Unfortunately Rules is very unstable in Drupal 8.

You need to find another solution. Maybe make a module with the hook presave node to check the values and update them.

Ok, thanks, I will try to program something
Regards,
Juan

You can use the following hook:

function module_name_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  //Checks If the node that is about to be created/updated is of type EN-CV Project
  if ($entity->bundle() == 'cv_project_new_template') {
    //Your code goes here
  }
}

Dear Juan and Sotirios

I follow the post from the beginning. My experience with rules was awful. Rules module was a great module in D7, with big used in our ALICE sites.
Rules in D8 was moved out from our project because isn’t finished and develop our code to replace.

Our schema is based in Events using the module “Hook Event Dispatcher” and our custom class called FieldChangedFunctions (evident the name)

Events => check if the event is relevant for us => stop the propagation => extract the change => make the response

For example in the class event check the subscriber

public static function getSubscribedEvents(){
return [
HookEventDispatcherInterface::FORM_ALTER => ‘hookFormAlter’,
HookEventDispatcherInterface::ENTITY_VIEW => ‘hookEntityView’,
HookEventDispatcherInterface::ENTITY_INSERT => ‘hookEntityInsert’,
HookEventDispatcherInterface::ENTITY_UPDATE => ‘hookEntityUpdate’,
HookEventDispatcherInterface::ENTITY_CREATE => ‘hookEntityCreate’,
HookEventDispatcherInterface::ENTITY_LOAD => ‘hookEntityLoad’,
HookEventDispatcherInterface::ENTITY_PRE_SAVE => ‘hookEntityPresave’
];
}



In the module

function alice_figure_node_was_updated(NodeInterface $node) {
//for event ENTITY_UPDATE => ‘hookEntityUpdate’,
//triggered in event
//seccion to check conditions to run this rules
$disabled = true;
$config = \Drupal::configFactory()->getEditable(‘alice_rules.settings’);
// disable or enable my own rules…
$disabled = $config->get(‘rules_all_disabled’);
if ($disabled) return; //Rules configurations

 //look for content type and field was changed 
 if ($node>isNew()) return; 
 // our class to detect changes in fields
 $field_changed = new FieldChangedFunctions; // Just to look if any field change 
   switch ($node->getType()) {// select the contenttype
    case "figure":
       // After updating content of type figure
       $changed_fields = $field_changed->entityHasChanged($node,'comment_node_figure');

       foreach($changed_fields as $field_nombre){// extract the correct fields and proccess
         switch($field_nombre){
          case 'field_fig_type': 
            //DRAFT 05 Notify EB first manuscript (not IRC nominated yet)

This is our way to replace rules…
We are open to share our experience.

Best regards
Guillermo Mesa
ALICE webmaster

Dear Guillermo,

Thank you for sharing this. I am sure it will help many people that search alternatives to Rules in Drupal 8.

Hi Sotirios and Guillermo,

I just finished my custom module. I used finally the entity_presave hook where I included my checks and it works nice and smooth. I first started creating a library on top of the override theme where to put js code but didn’t like it. I think creating a module and using the hook is a better approach and more Drupal oriented.

For anyone trying to deal with rules (both rules and business rules modules), in my experience, they just work with very simple rules.

The business rules module is pretty nice, having more advanced options but still has some bugs (some of them waiting for a patch for almost 1 year).

Thanks