![]() I leave the Usage set as “Parameter”Īfter clicking the “Save Changes” button, I am then presented with two sections that make up my Rules Component, “Conditions” and “Actions.” Conditions provide a means to evaluate elements of an object or field as “true” before firing the associated Actions. Thus, I will identify my variable Data Type as “Entity: Node” and assign “shipnode” as both a label and machine name so I can identify it as I go about creating my Rules Component. I am expecting my Rules Components to be passed a single, complete node object. These variables may expected to passed to the Rules Component individually, or as part of a list. Basically, the data types of variables that I might expect are either going to be full entity objects (node, taxonomy, etc) or a particular field type of an expected format (date, ip address, text, integer, etc.). I then determine which variables I expect to be passed to my Rule Component. My first Rules Component will adjust the shipping date in the node, so I have named the overall Rules Component “Ship Change.” Choosing the Drupal Rule Component Plugin, “Rule”Īfter selecting the Rule plugin, I then add a name for my Rules Component and optionally add tags to help classify my Rule. The other plugins may be useful for only content evaluation, actions to change content, or calling other rules and are used lest often. In this case, I am going to implement a “Rule” which provides both the means to identify and act on the content I want to change. When setting up a Rules Component, I first need to identify what kind of “Component plugin” I want to use. Why do I use Rules Components over regular “reaction” Rules? Well, unfortunately, if I set up Rule to be triggered by Rules Scheduler or a periodic System event such as a cron or Drupal initialization, there will be no node object data associated with these events to act on! Thus, I’ll need to get these node objects by another method in order to apply Rules to them and in this particular “pass through” situation only Rules Components are going to work. I’ll start by setting up two Rules Components for implementing the changes to the shipment date and original shipment date. I want this Rule to be automated and not necessarily triggered by a user. For those shipments that are not complete and the shipment date is past the current date, I want to 1) copy the current shipment date to another date field, original shipment date, if the original shipment date is empty, and 2) update the shipment date to the current date. I have a node content type for tracking shipments, it includes fields for a shipment date and whether it is completed or not. To help explain Rules, let me explain my recent Rules project which requires the use of both a reaction Rule and Rule Components, as well as the use of Views Bulk Operations. Rule Components can also be scheduled to fire using the Rules Scheduler module, included with Rules. ![]() A Rule Component is usually called by another Rule or within a module. This data is usually a node, user or other entity object, or perhaps, a list of fields to be acted on. Rule Components, on the other hand, require you identify the kind of data that you expect to be passed to it. With these triggered events, the corresponding content entity object, such as a node (title, body, author, custom fields, etc.), is made available to the Rule to act on. Reaction Rule events include when a node is published, a user logs in or a comment is made. The main difference between the two are that “reaction” rules are set to fire on certain “events” that happen on your website while Rule Components only act on data that is passed to them. Rules come in two main flavors, regular “reaction” Rules and Rules Components. Rules Scheduler can also be helpful if you want to be able to activate a Rule Component close to a specific date and time. Make sure you activate both the Rules and Rules UI modules. While you can use Trigger and Rules modules at the same time, you’ll probably want to use Rules for any custom automation or workflow actions in your Drupal site. It is similar to the Trigger module provided with Drupal Core but provides a greater range of functionality. Rules provides the means to program your website to do actions when certain events occur. If you’ve spent some time with Drupal you’ve probably come across the Rules module. This post is based on my own project where certain fields of a node need to be periodically updated based on the data of other fields in the node. It discusses the differences between a Rule and Rule Component how to use Rules to identify, evaluate and modify associated fields of a node or other entity and how to pass data to a Rule with the help of Views Bulk Operations. This post is primarily focused on how to use the Rules module to automate actions on your Drupal site.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |