1

I'm trying to create a rule for new node content that is based on entity references.

To give some background I have story pages and chapter pages. The story pages are story meta data, the chapters are real content. The chapters reference the story pages and are sorted by chapter numbers set by the users.

I want to create a rule for when a new chapter is published. But it needs to be able to evaluate a field on the Story the chapter is a part of. How do I get rules to go to that story entity in question and check the value of the fields in question?

  • Does your entity reference field allow for unlimited values, or only 1 value is allowed? – No Sssweat Dec 25 '16 at 14:46
  • The Field in question only allows one entry. A chapter is part of one story. So that story entity is NOT competeing with anything else. – CW Smith Dec 25 '16 at 14:49
  • I gtg, so here is the short story: you will need to create a component, and possibly 2 of them. Long story: wait for @Pierre.Vriens to answer this. – No Sssweat Dec 25 '16 at 14:55
  • please tell us what is suppose to happen when this condition is true? does something get altered in chapter or in story? – No Sssweat Dec 25 '16 at 14:59
  • Well the condition, when true will continue on and publish a post to twitter and Facebook, specific pages and accounts depending on certain values.. When it's false it will stop. – CW Smith Dec 25 '16 at 15:00
1

Okay, I think I figured out a way to pull this off, and even if it's not the best practice for what I'm attempting to do, it is working.

So like I said, I was trying to create a condition that relies on information contained in a node that is being referenced as an entity. One of the discussion posts indicated I may need to create a component.

So I went to components and created a new component. Data type I set for Any Entity then named it story page (story_page).

I set conditions that the entity is content, and then a condition where content is of type story page.

Now that we have the content type identified and set we create a condition for list contains item and search for the item in the specific taxonomy I'm looking for. 

TO understand this component understand that there are some folk who post more mature content on my page that I DON'T want exposed to the general public. So I require that that kind of content be marked by a specific setting in two fields.

This checks one of those fields and makes the determination. The information however on a chapter for that to be determined is stored in a referenced node which is set in field_story. You have to be able to get the information from that node, and that information is stored in field_genre. So the Componenet is built like this.

{ "rules_check_for_erotica" : {
"LABEL" : "Check for Erotica",
"PLUGIN" : "and",
"OWNER" : "rules",
"TAGS" : [ "Entity Reference", "Node", "Twitter" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "story_page" : { "label" : "Story\u00a0Front Page", "type" : "entity" } },
"AND" : [
  { "entity_is_of_type" : { "entity" : [ "story-page" ], "type" : "node" } },
  { "node_is_of_type" : {
      "node" : [ "story-page" ],
      "type" : { "value" : { "story_front_page" : "story_front_page" } }
    }
  },
  { "list_contains" : { "list" : [ "story-page:field-genre" ], "item" : "161" } }
]

} }

Now, we have a component that can test and figure out if the attached story field has that entry. We can then use it for rules related to story pages to test for it, and make a determination on what to do based on it.

I then created another rule similar to this but it was checking a different field to determine if the story in question is an original story or if it's part of an original series on this page. I then created a new rule to check the chapter page.

{ "rules_publish_new_chapter_darkscribes_" : {
"LABEL" : "Publish New Chapter (Darkscribes)",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "Facebook", "Social", "Twitter" ],
"REQUIRES" : [ "rules", "twitter_actions", "fb_autopost_entity" ],
"ON" : { "node_insert--chapter_page" : { "bundle" : "chapter_page" } },
"IF" : [
  { "component_rules_check_for_original" : { "story_page" : [ "node:field-story" ] } },
  { "NOT component_rules_check_for_erotica" : { "story_page" : [ "node:field-story" ] } }
],
"DO" : [
  { "rules_core_twitter_actions_set_status_action" : {
      "message" : "[node:author] just posted a new chapter for [node:field_story] | Chapter [node:field-chapter-no-]: [node:title] | [node:url]",
      "sender" : "Darkscribes"
    }
  },
  { "entity_create" : {
      "USING" : {
        "type" : "facebook_publication",
        "param_type" : "post",
        "param_user" : [ "site:current-user" ]
      },
      "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
    }
  },
  { "data_set" : {
      "data" : [ "entity-created:field-facebook-link" ],
      "value" : [ "node:url" ]
    }
  },
  { "data_set" : {
      "data" : [ "entity-created:field-facebook-message" ],
      "value" : [ "node:body:summary" ]
    }
  },
  { "publish_to_facebook" : {
      "USING" : { "publication" : [ "entity-created" ], "pages" : "215544991848808" },
      "PROVIDE" : { "facebook_publication_id" : { "facebook_publication_id" : "Facebook publication returned ID" } }
    }
  },
  { "data_set" : {
      "data" : [ "facebook-publication-id" ],
      "value" : [ "facebook-publication-id" ]
    }
  },
  { "entity_save" : { "data" : [ "entity-created" ] } }
]

} }

I tested it to see if it would post a message to one of the two twitter accounts in question, and it SEEMS to have done just right.

I may need to revisit this answer later and add an image or screenshot to it at some point. Or find a way to consolidate my content checking rules.

  • Nice, good to hear that my comment lead you to the answer. :-) – No Sssweat Dec 26 '16 at 1:19
  • Maybe you should also include an export of your rule and component ... – Pierre.Vriens Dec 26 '16 at 6:28
  • Understood Pierre.Vriens. I've added that and some more explanation to what is happening in the rules. I'm not sure if it's perfect, but it's what I've done. – CW Smith Dec 26 '16 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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