我试图为新的节点内容创建一个基于实体引用的规则。
为了给一些背景,我有故事页和章节页。故事页面是故事元数据,章节是真实的内容。这些章节引用故事页,并按用户设置的章节编号进行排序。
我想为新章节的发布创建一个规则。但它需要能够评估一个领域的故事,这一章是一部分。我如何获得规则,以进入该故事实体,并检查有关字段的值?
发布于 2016-12-25 20:31:54
好吧,我想我想出了一个办法来完成这个任务,即使这不是我想要做的最好的方法,它也是有效的。
所以就像我说的,我试图创建一个依赖于作为实体引用的节点中包含的信息的条件。其中一篇讨论文章指出,我可能需要创建一个组件。
所以我去了组件并创建了一个新的组件。我为任何实体设置的数据类型,然后将其命名为故事页(story_page)。
我设置了实体是内容的条件,然后设置了内容类型为“故事页”的条件。
现在,我们已经识别和设置了内容类型,我们创建了一个条件,用于列表包含项,并在我要寻找的特定分类中搜索条目。
要理解这个组件,请理解,有些人在我的页面上发布了更成熟的内容,我不想向公众公开这些内容。因此,我要求在两个字段中用特定的非特定设置来标记这类内容。
这将检查其中一个字段并作出决定。然而,用于待确定的章节上的信息存储在在field_story中设置的引用节点中。您必须能够从该节点获取信息,并且该信息存储在field_genre中。所以这个组件就是这样构建的。
{ "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" } }
]}}
现在,我们有了一个组件,它可以测试并确定附加的故事字段是否包含这个新条目。然后,我们可以使用它作为与故事页相关的规则来测试它,并在此基础上确定该做什么。
然后,我创建了另一条类似于此的规则,但它正在检查一个不同的字段,以确定所讨论的故事是否是原始故事,还是本页原始系列的一部分。然后,我创建了一个新规则来检查章节页。
{ "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" ] } }
]}}
我对它进行了测试,看看它是否会将消息发送给两个twitter账户中的一个,它似乎做得很好。
我可能需要重新讨论这个答案,并在某个时候添加一个图片或屏幕截图。或者找到一种方法来巩固我的内容检查规则。
https://drupal.stackexchange.com/questions/223857
复制相似问题