0

I have to redirect to specific page for article content based on the its entity reference field value

Eg : article content having field_test2(field_name) reference to sample / 10164( taxonomy reference field value ) should be redirect to events

I have done this in rules. But the page redirection is not working. I have printed all the variables in article twig all are same but redirection not working.

status: true
dependencies: {  }
id: test_workflow_rules
label: 'Test Workflow rules'
events:
  -
    event_name: 'rules_entity_view:node--article'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 48cf31fd-db17-4f6a-ad75-71e9ea7b6b06
  weight: 0
  conditions:
    id: rules_and
    uuid: 3c51e865-1f88-429d-b363-bd7ed62a018f
    weight: 0
    conditions:
      -
        id: rules_condition
        uuid: 45c0f11a-34a3-487d-9e1c-30b3300ee9bf
        weight: 0
        context_values:
          type: article
          bundle: article
        context_mapping:
          entity: node
        context_processors:
          type:
            rules_tokens: {  }
          bundle:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_entity_is_of_bundle
        negate: false
      -
        id: rules_condition
        uuid: 647b13df-27ec-4c53-88fb-aa010c9e0021
        weight: 0
        context_values:
          operation: '=='
          value: '10164'
        context_mapping:
          data: node.field_test2.entity.tid.value
        context_processors:
          operation:
            rules_tokens: {  }
          value:
            rules_tokens: {  }
        provides_mapping: {  }
        condition_id: rules_data_comparison
        negate: false
  actions:
    id: rules_action_set
    uuid: 2f6d63e8-fb96-4014-b504-900d4763aa08
    weight: 0
    actions:
      -
        id: rules_action
        uuid: 48790fb3-7658-45df-8a8d-ecc6e0f83ff0
        weight: 0
        context_values:
          url: /events
        context_mapping: {  }
        context_processors:
          url:
            rules_tokens: {  }
        provides_mapping: {  }
        action_id: rules_page_redirect

The module version - 8.x-3.x-dev

Removing the data comparison and entity is of bundle , the redirection works.

2

Your conclusion is wrong. You say that page redirection does not work, but what is really happening is that your conditions are configured wrong so the redirect action is never used.

For the rules_entity_is_of_bundle condition, you have:

      type: article
      bundle: article

But articles are node types, so the type: should be node. This condition will never be true because of the way you've configured it.

In general, you should debug your Rules one step at a time and use the rules_system_message action to display a message on the screen for debugging. First use just the event and the system message action to ensure the message is shown when you expect them. Then add conditions one at a time to see if the conditions evaluate as you expect them to. You can use the system message action to display the values of data like {{ node.field_test2.entity.tid.value }}, which will help you see whether the values are what you expect. After you have the conditions working the way you want, then add the redirect action.

You can also turn on Rules debug logging to see what Rules are being triggered, by what events they're being triggered, and see the result of each condition evaluation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.