Select Page

How to be able to access custom fields of a custom Content Type

So I wanted to have a Workflow Rule in Drupal (module: rules) where one of the conditions is a “Data Comparison” based on a specific field (let’s say total_price) of a Custom Content Type I made (let’s say type Course).

So as event selection I selected “After updating a content item” in the “Reaction on event” select box. And chose my content type (Course) in the “Restrict by type” select box.

I thought that was enough to make the rule aware of my Custom Content Type.

However, it seems by default that’s not possible out-of-the-box. I got errors like:

Data selector node.field_total_price.value for context Data to compare is invalid. Unable to apply data selector ‘field_total_price.value’ at ‘field_total_price’


The trick is to add first a condition of type “Entity is of bundle”. See image below.

Once you do that, you’ll see that a lot more auto-completion items popup when you start typing.


How to format Recipienst (TO Field) in “Send Email” in Action

It took me some research work to find the correct notation to specify recipients in the “SEND TO” (within context variables).

I got Errors like

TypeError: Argument 1 passed to Drupal\rules\Plugin\RulesAction\SystemSendEmail::doExecute() must be of the type array, object given in Drupal\rules\Plugin\RulesAction\SystemSendEmail->doExecute() (line 112 of /srv/users/serverpilot/apps/soutienscolaire/public/modules/rules/src/Plugin/RulesAction/SystemSendEmail.php)


InvalidArgumentException: Cannot set a list with a non-array value. in Drupal\Core\TypedData\Plugin\DataType\ItemList->setValue() (line 59 of /srv/users/serverpilot/apps/soutienscolaire/public/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php).

After some googling I found this format is the correct one, which makes it an array instead of a simple value.

{{ node.field_teacher.entity.mail }}