如何创建 Drupal 规则以检查(在 cron 上)日期字段以及是否通过设置字段“状态"到“结束"? [英] How to create a Drupal rule to check (on cron) a date field and if passed set field "status" to "ended"?

查看:16
本文介绍了如何创建 Drupal 规则以检查(在 cron 上)日期字段以及是否通过设置字段“状态"到“结束"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建自定义规则(使用 Rules 模块),以便每次 cron 运行时,此规则都会检查我创建的自定义内容类型中的日期字段.如果该日期已过,那么我想将列表小部件从 active 设置为 ended.

I'm trying to create a custom rule (using the Rules module) so that every time the cron runs, this rule checks a date field in a custom content type I created. If that date has passed then I want to set a list widget from active to ended.

这是我尝试创建此规则时的结果:

This is how far I get when trying to create this rule:

  1. React on event 设置为 Cron 维护任务已执行
  2. 添加条件 > 设置选择要添加的条件数据比较 > 继续
  1. Set React on event to Cron maintenance tasks are performed
  2. Add Condition > Set Select the condition to add to Data comparison > Continue

问题出在:数据选择器只有site,不能访问字段数据.

Here is the issue: Data selectors only has site and no access to field data.

有什么想法我在这里出错了吗?

Any ideas where I'm going wrong here?

推荐答案

是的,您应该能够使用 Rules 模块来实现你正在寻找的东西,但我建议你也将它与 查看规则 模块.关于这个模块的一些细节(来自它的项目页面):

Yes you should be able to get this to work using the Rules module to implement what you're looking for, but I recommend you to also combine that with the Views Rules module. Some details about this module (from its project page):

将视图直接作为规则操作和循环提供,以无缝使用视图结果数据.

Provides Views directly as Rules actions and loops to seamlessly use view result data.

前面的引用可能看起来有点神秘(它可能会让你想那又如何,这对我有什么帮助?").因此,有关如何使用这些模块继续前进的更多详细信息:

The previous quote may seem a bit cryptic (it may make you think like "so what, how can this help me?"). Therefor some more details about how to move forward using these modules:

  1. 创建一个视图(使用 Views),以便您有 1 个视图结果(行)包含您要处理的所有节点(与您的自定义内容类型相关,如果可能,请使用您的日期字段以某种方式过滤).而该视图具有后续步骤中所需的任何字段(列),例如节点 ID、日期字段以及可能的其他字段.稍后您将需要这些视图字段作为您的规则处理的值,将列表小部件从 active 设置为 ended*"(如您的问题所示).重要提示:使用规则"的视图显示类型.
  2. 删除添加条件"(在您启动的自定义规则中),改为使用 视图使用称为规则循环"的规则技术,使用称为规则循环"的规则技术对这些视图中的每一个进行迭代的规则 模块会导致规则操作.
  3. 对于规则循环中的每个迭代步骤,执行规则操作以做你的事"(= 将列表小部件从 active 设置为 ended).届时,您将拥有来自视图结果每一列的所有数据,即所谓的规则参数.因此,此时为您在该循环中处理的节点调整该列表小部件的值是小菜一碟.
  4. 或者,您可能还想添加任何额外的规则条件,这也取决于您自己的想象.通常,您不能或尚未将其表示为视图过滤器.但是,如果您可以在使用视图过滤器和额外的规则条件之间进行选择,我建议您使用视图过滤器,因为这将减少您在规则循环中的迭代次数(性能!).
  1. Create a view (using Views) so that you have 1 Views result (row) with all the nodes you want to be processed (related to your custom content type and if possible filter somehow using your date field). Whereas that view has fields (columns) for whatever is needed in subsequent steps, e.g the node ID, the date field, and possibly other fields as well. You'll need these View fields later on as values to be processed by your rule, "to set a list widget from active to ended*" (as in your question). Important: use a Views display type of "Rules".
  2. Remove that "add condition" (in the custom rule you started) and, instead, use the Views Rules module to iterate over each of these Views results in a Rules action, using the Rules technique known as a "Rules Loop".
  3. For each iteration step in your Rules loop, perform a Rules Action to "do your thing" (= to set a list widget from active to ended). At that point you'll have all data from each column of your Views results available as so called Rules Parameters. So at that point it's a piece of cake to adapt the value of that list widget for the node you're processing in that loop.
  4. Optionally, you may also want to add whatever extra Rules Condition(s), also up to your own imagination. Typically the things you cannot, or have not yet, expressed as a Views filter. However, if you have a choice between using a Views filter and an extra Rules Condition, I recommend to go for the Views filter, because that will reduce the number of your iterations in your Rules loop (performance!).

简单,不是吗?

这篇关于如何创建 Drupal 规则以检查(在 cron 上)日期字段以及是否通过设置字段“状态"到“结束"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆