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
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
Comment #3
krystalcode commentedI 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.
Comment #4
lobsterr commentedLeave it to me I will check it from this point
Comment #5
lobsterr commented@krystalcode your fix solves the issue. Please share other problems you see, I have checked the code entity cardinality checks work as expected.
Comment #8
lobsterr commentedThank you for your contribution