Example default rules

SocialHub entities come with default example rules that you can build your own rules upon.

Note that you need to enable Rules UI and SocialHub reference to make use of these rules.

Example rule: SocialHub comment sync - send new comments

This rule will send new published comments to SocialHub.

It begins by loading all referenced SocialHub Posts of the comment's node and iterates through them. For each Post a new SocialHub comment entity is created, with the value of the comment body field as comment content. It sets the current User's name (which should be the name of the comment author in the moment the Rule is executed) and his user page as author data. And saves the SocialHub comment which triggers the API request to be sent.

Events

  • Before saving a comment

Conditions

  • Data comparison: [comment:status] == Published
  • Data comparison: [comment-unchanged:status] == Unpublished

Actions

  • Load all referenced SocialHub post of a node ([comment:node])
  • Loop (for each referenced [post])
    • Create a new (SocialHub comment) entity
    • Set a data value: [socialhub-comment:socialhub-reference-comment] = [comment]
    • Set a data value: [socialhub-comment:plain-content] = [comment:comment-body:value]
    • Set a data value: [socialhub-comment:author] = [site:current-user:name]
    • Set a data value: [socialhub-comment:author-link] = [site:current-user:url]
    • Save entity (SocialHub comment)

Example rule: SocialHub comment sync - receive new comments

This rule will react on received, new comments from SocialHub and create Drupal comments on a node.

It reacts after a new SocialHub comment is inserted, to prevent infinite recursion with the rule above we have to check that this events source is external. Then it loads the SocialHub Post that is referenced in the received SocialHub comment and creates a new Drupal comment entity. It sets the received author data and comment contents and saves it for the node referenced in the loaded Post.

Events

  • After saving a new socialhub comment

Conditions

  • Data comparison: [source] == External event

Actions

  • Fetch entity by id ([socialhub-comment:post-sid])
  • Create a new (Comment) entity
  • Set a data value: [comment:name] = [socialhub-comment:author]
  • Set a data value: [comment:homepage] = [socialhub-comment:author-link]
  • Set a data value: [comment:comment-body:value] = [socialhub-comment:html-content]
  • Save entity (Comment)