Skip to content

Commit

Permalink
Issue #3487220: Fix user group list
Browse files Browse the repository at this point in the history
In the database we have table "group_relationship_field_data"
which is the data table for group content entities.
In this table, we can see the columns type, group_type and plugin_id.

The pattern for the group membership type is usually
<group_type>-<plugin>. The type (column) is limited to 32 characters,
and for example closed_challenge-group_membership (33 characters)
is just too long.

Group includes a way to generate names that fit the limits
imposed by Drupal core, and it does this consistently in its
own code. However, this means that where a <bundle>-<plugin>
concatenation would exceed the limit, it instead converts it to
'group_content_type_' . md5($preferred_id) and truncates it.
This is done in GroupRelationshipTypeStorage::getRelationshipTypeId.
The problem is that our code is naively looking at the
concatenation and doesn't handle the "too long" case, which
is handled by the group module.

To solve the problem, we replaced the "type" condition in the
database query with the "plugin_id" condition, because
we do not need the relationship "type", which is unique per
plugin_id and group_type. Since group_type is always the
same per group entity (and we filter per entity), filtering
by "plugin_id" instead of "type" gives the expected result.
  • Loading branch information
zanvidmar committed Nov 14, 2024
1 parent 1dcc33d commit 97de4ef
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function query($group_by = FALSE) {
$subselect2 = $this->database->select('group_relationship_field_data', 'gc');
$subselect2->addField('gc', 'gid');
$subselect2->condition('gc.entity_id', $this->argument);
$subselect2->condition('gc.type', '%' . $this->database->escapeLike('membership') . '%', 'LIKE');
$subselect2->condition('gc.plugin_id', '%' . $this->database->escapeLike('membership') . '%', 'LIKE');

if ($this->usesOptions && isset($this->options['group'])) {
$this->query->addWhere($this->options['group'], $this->tableAlias . '.id', $subselect2, 'IN');
Expand Down

0 comments on commit 97de4ef

Please sign in to comment.