Entity is of bundle on entity reference field

Created on 5 April 2023, over 1 year ago
Updated 30 October 2023, about 1 year ago

Problem/Motivation

I'm trying to create a rule, which would feature a condition based on referenced entity's field value,
but I'm getting an error in Drupal\rules\Plugin\Condition\EntityIsOfBundle->assertMetadata(). I'm not sure if I'm using the parameters wrong or it is an error.

Steps to reproduce

1. Create a new rule with the following Event: "Entity of type content item is viewed"
2. Create a condition to access the node's fields: Condition: "Entity is of bundle" Parameters: "entity: node, type: node, bundle: article"
3. Create a second "Entity is of bundle" condition to access the referenced entity fields with the parameters:
"entity: node.field_basic_page.entity, type: node, bundle: page"
4. Get Error: Call to undefined method Drupal\Core\TypedData\DataReferenceDefinition::setBundles() in Drupal\rules\Plugin\Condition\EntityIsOfBundle->assertMetadata() (line 71 of modules/contrib/rules/src/Plugin/Condition/EntityIsOfBundle.php).
5. I tried in #3 Parameters: "entity: node.field_basic_page, type: node, bundle: page" with Error: Call to undefined method Drupal\field\Entity\FieldConfig::setBundles() in Drupal\rules\Plugin\Condition\EntityIsOfBundle->assertMetadata() (line 71 of modules/contrib/rules/src/Plugin/Condition/EntityIsOfBundle.php).

🐛 Bug report
Status

Active

Version

3.0

Component

Rules Core

Created by

🇺🇸United States dmitryl Austin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dmitryl
  • 🇺🇸United States tr Cascadia

    In the future please search the issue queue before posting. There is already an open issue for this which you could have helped with 💬 Cannot execute "Entity is of bundle" condition on a referenced entity Closed: duplicate .

    Also please export your Rule as a YML file, because describing what you used for inputs is not precise or complete. It's hard to tell if you made a mistake in your input.

    I'm leaving this open as a bug because there are more details than that older issue.

    the error here, Call to undefined method Drupal\Core\TypedData\DataReferenceDefinition::setBundles(), is happening because this data value is supposed to be an EntityDataDefinition, not a DataReferenceDefinition. There probably needs to be a call to DataReferenceDefinition::getTargetDefinition() somewhere to dereference the entity.

  • 🇺🇸United States dmitryl Austin

    Thank you for the clarification. The referenced issue is with 8.x-3.0-alpha7 version though, which I filtered out, but I'll keep that in mind. Attaching the rule config.

  • 🇨🇳China splash112

    This issue might be a duplicate of the following:

    https://www.drupal.org/project/rules/issues/3059402 🐛 Set data action in referenced entity. Needs work

  • 🇮🇳India Shreya_98

    Hi @dmitryl,
    I have fixed this issue and also provided patch for this issue . Kindly review the patch file.

Production build 0.71.5 2024