Problem/Motivation

While relation type plugins provide the configuration available to relationship types, the actual values configured are stored in the relationship type configuration entity. Therefore, if you have multiple group types that you can add media to, you may have different configured values for each.

The AttachMediaToGroup::assignMediaToGroups() method allows assigning multiple media entities to multiple groups. However, it caches the plugin configuration that it uses to calculate the entity/group cardinality based on the plugin ID. If multiple groups of different types but using the same plugin are given, then the cached configuration will be wrong - leading to false results.

Moreover, the current logic that calculates whether the group cardinality limit has been reached counts all relationships for the plugin - while it should count all relationships for the relationship type. It therefore falsely skips creating relationships when it shouldn't.

Reading the code, similar bug seems to exist when calculating the entity cardinality, but I have not tested that.

Finally, I only reviewed the VGO actions and the AttachMediaToGroup service, there may be other code in the module that suffers from similar bugs.

Steps to reproduce

1. Create two group types to which you can add media items of the same bundle.
2. Enable the relation type plugin for both group types and set group cardinality to 1.
3. Create a media item and two groups - one of each type.
4. Add the media item to both using VBO.
5. Observe that the media item refuses to be added to the second group.

Proposed resolution

- The AttachMediaToGroup needs some refactoring to properly get the configuration for each relationship type, and not cached from another relationship type that uses the same plugin.

- The logic that calculates group/entity cardinality violations needs refactoring so that it counts relationships for the group type and not per plugin.

Issue fork groupmedia-3585683

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

krystalcode created an issue. See original summary.

krystalcode’s picture

Status: Active » Needs work

I created an MR with a quick fix for the group cardinality issue when assigning to one group only, but there is a lot more work needed to properly fix the bugs that affect different cases.

lobsterr’s picture

Leave it to me I will check it from this point

lobsterr’s picture

@krystalcode your fix solves the issue. Please share other problems you see, I have checked the code entity cardinality checks work as expected.

  • lobsterr committed c18bf7a9 on 3.0.x
    feat: #3585683 Plugin configuration varies per relationship type and not...
lobsterr’s picture

Status: Needs work » Fixed

Thank you for your contribution

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • lobsterr committed e7d7534e on 8.x-2.x
    feat: #3585683 Plugin configuration varies per relationship type and not...

Status: Fixed » Closed (fixed)

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