I am trying to tweet after saving a content that is published. I get the following error:
TypeError: Argument 1 passed to Drupal\rules\Plugin\Condition\NodeIsPublished::doEvaluate() must implement interface Drupal\node\NodeInterface, string given in Drupal\rules\Plugin\Condition\NodeIsPublished->doEvaluate() (line 35 of modules/contrib/rules/src/Plugin/Condition/NodeIsPublished.php).
and following is an export of my rule:

uuid: 976dece1-8e0f-46ff-a852-b00452a9d664
langcode: en
status: true
dependencies: {  }
id: tweet_posted_content
label: 'tweet posted content'
events:
  -
    event_name: 'rules_entity_insert:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: d494c05c-d547-4baf-a229-2ce233f5b850
  conditions:
    id: rules_and
    uuid: 311a03ae-df53-45fa-bf5e-dd9d26abe474
    conditions:
      -
        id: rules_condition
        uuid: eaa0fd3e-3d63-47e4-b6d5-3237e57642b1
        context_values:
          node: '1'
        context_mapping: {  }
        context_processors:
          node:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_node_is_published
        negate: false
  actions:
    id: rules_action_set
    uuid: 48c84309-4a2e-4852-922e-c119f2ad831c
    actions:
      -
        id: rules_action
        uuid: d3a7b994-cf23-4df1-af3b-0c69668cc64c
        context_values:
          status: 'محتوى جديد بعنوان: {{ node.title.value }} {{ node | entity_url }}'
        context_mapping: {  }
        context_processors:
          status:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: social_post_twitter_tweet

what is the correct way to check for node is published? an example rule will be much appreciated.

Comments

mohammed76 created an issue. See original summary.

tr’s picture

Issue summary: View changes
tr’s picture

Status: Active » Fixed

The error is because you used the input value "1" in the data selector in your "Node is Published" condition, but Rules expects a node object so you should have used "node" in direct input mode.

Here is a working Rule that fixes the problem - you may import this and examine it to see how to use that condition properly. I don't have the "social_post_twitter_tweet" action on my site so I used "Show a message on the site", which BTW is a lot easier to use for debugging! First get it working with the message, then you can replace the message with your own action.

langcode: en
status: true
dependencies: {  }
id: tweet_posted_content
label: 'tweet posted content'
events:
  -
    event_name: 'rules_entity_insert:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: d494c05c-d547-4baf-a229-2ce233f5b850
  conditions:
    id: rules_and
    uuid: 311a03ae-df53-45fa-bf5e-dd9d26abe474
    conditions:
      -
        id: rules_condition
        uuid: eaa0fd3e-3d63-47e4-b6d5-3237e57642b1
        context_values: {  }
        context_mapping:
          node: node
        context_processors: {  }
        provides_mapping: {  }
        condition_id: rules_node_is_published
        negate: false
  actions:
    id: rules_action_set
    uuid: f9b01efe-ace3-4d14-b9d0-288cfbddfb7c
    actions:
      -
        id: rules_action
        uuid: 0edfbaf7-7687-4d2b-bbc4-e1665d059574
        context_values:
          message: 'محتوى جديد بعنوان: {{ node.title }} {{ node | entity_url }}'
          type: warning
          repeat: false
        context_mapping: {  }
        context_processors:
          message:
            rules_tokens: {  }
          type:
            rules_tokens: {  }
          repeat:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_system_message
aiphes’s picture

Hi, I have a question related to twig token in rules (sending mail). Do exist a list or a documentation to how to know which tokens are available to use in rules ,like a message send by the "send email" action. ?

thanks

mohammed76’s picture

@aiphes just a friendly advice: I would open a new support request rather than asking an unrelated question in an already closed one.
That said, I don't think there exist any such list. what I usually do is to try to use the data selector to drill down into available words and then use them in the same style of a twigg token. {{ token.token }}

aiphes’s picture

Thanks for tips and advice ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.