Hello,

I'm trying to create a Pathauto pattern for a content type based off of the group(s) that a node is associated with. So, for example, I have a content type called About, and this content type is made available to a group type called Department. Groups that are within the Department group type include Biology and Chemistry. Ideally, when an About node is created and associated with a given group, I'd like to have the path for the node to be generated via Pathauto pattern as something like [node:group:title]/[node:title]. However, there's no token available to do anything like this for a content pattern type. How could this be done? Thank you for any help.

CommentFileSizeAuthor
#130 interdiff-128-130.txt1.53 KBevilehk
#130 2774827-node-parent-group-token-130.patch6.08 KBevilehk
#128 2774827-node-parent-group-token-128.patch5.45 KBevilehk
#127 2774827-127.patch4.05 KBbryanmanalo
#93 group-2774827-93.patch4.63 KBkroh
#90 group-2774827-90-gnode-tokens-updated-for-3.0.x-dev.patch4.64 KBthatguy
#89 group-2774827-89-gnode-tokens-updated.patch5.15 KBdipanjan.kundu
#77 group-gnode_tokens-2774827-75.patch6.5 KBrzb
#74 group-gnode_tokens-2774827-74.patch6.39 KBkekkis
#72 group-gnode-tokens-2774827-72.patch3.13 KBsafetypin
#71 group-gnode_tokens-2774827-68--against-1.3.patch3.13 KBkekkis
#62 group-gnode_tokens-2774827-62.patch6.39 KBr-mo
#61 group-gnode_tokens-2774827-61.patch6.41 KBr-mo
#59 group-gnode_tokens-2774827-59.patch5.01 KBr-mo
#41 group-2774827-41-gnode-tokens.patch5.15 KBgeek-merlin
#41 group-2774827-interdiff-40-41.txt690 bytesgeek-merlin
#40 interdiff_36-40.txt1.32 KBfloydm
#40 group_add-node-group-tokens-2774827-40.patch4.54 KBfloydm
#36 group_add-node-group-tokens-2774827-36.patch4.27 KBorbmantell
#24 group_add-node-group-tokens-2774827-24.patch4.28 KBericras
#22 group_add-node-group-tokens-2774827-22.patch2.44 KBrachel_norfolk
#20 group_add-node-group-tokens-2774827-20.patch1.84 KBrachel_norfolk
#16 token-error-editing-node.png72.85 KBrogertcd
#13 group_add-node-group-tokens-2774827-13.patch3.47 KBzerolab
#11 group_add-node-group-tokens-2774827-11.patch2.4 KBzerolab
#5 group_add-node-group-tokens-2774827-5.patch1.66 KBzerolab
#3 no-group-token.png570.63 KBcainaru

Issue fork group-2774827

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

cainaru created an issue. See original summary.

cainaru’s picture

Version: 8.x-1.x-dev » 8.x-1.0-beta1
cainaru’s picture

StatusFileSize
new570.63 KB
zerolab’s picture

You will need to define that token in gnode.tokes.inc. This is great candidate for a patch.

See node_token_info(), node_tokens, group_token_info() and group_tokens() for group-related tokens.

zerolab’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.66 KB

Here's a first attempt at that.

The patch exposes all group tokens for nodes. [node:group:title]/[node:title] will default to [node:title] if the node does not belong to a group. Also, taking only the first returned group, in case the node belongs to more than one.

Will look at providing tests as well.

kristiaanvandeneynde’s picture

+++ b/modules/gnode/gnode.tokens.inc
@@ -0,0 +1,59 @@
+  $group_content = array_pop($group_content_array);

Seeing as nodes can now have multiple parents, why not create a [node:group] token as an array of groups? If you configured the group_node plugin to only allow for one parent (through the UI), then you can use the tokens with the delta 0.

If you do, however, allow for multiple parents, then at least we also have tokens covering that use case.

rachel_norfolk’s picture

Status: Needs review » Needs work

Hmm - running group beta1 with the patch applied is allowing me to choose the tokens but they are not creating paths that include that extra information.

path pattern added:

tstories/[node:group:author]/[node:group:title]/[node:title]

what i’m actually getting is:

tstories/[node:title]

zerolab’s picture

I tested by assigning an existing node to a group, then re-saving the node.
It is quite possible that the issue here is that the node is first created than assigned to the group. So the alias does not have the group context, hence the simple title.

OG solves this by having an ER field directly on the node, rather than having the extra step in the node form.

@kristiaanvandeneynde very good point re multiple parents. What should the default be? For example Node A belongs to Group 1 and Group 2, while the token is [node:group:title]/[node:title].
It is also worth noting to that from what I could find, array support only comes with the Token module, so that will need to at least come as a soft dependency.

kristiaanvandeneynde’s picture

The node is indeed saved first so the interstitial GroupContent entity can have both a node and group ID to refer to. I don't see any reason why we couldn't do something like this, though:

$node->save();
// Grab the NID
$group_content->save();

// We save the node again because blah blah...
$node->save();
kristiaanvandeneynde’s picture

@kristiaanvandeneynde very good point re multiple parents. What should the default be? For example Node A belongs to Group 1 and Group 2, while the token is [node:group:title]/[node:title].
It is also worth noting to that from what I could find, array support only comes with the Token module, so that will need to at least come as a soft dependency.

I would default to delta 0 for any non-specific token use. E.g. [node:group] returns the first group affiliation it can find. We'd need to make sure the list is consistent, though. Like, sort it by GroupContent ID so new group affiliations are appended to the list instead of inserted in there at random.

You're right about the Token module: If that is what enables list tokens, we'd need to support both scenarios (with/without Token).

zerolab’s picture

Status: Needs work » Needs review
StatusFileSize
new2.4 KB

Here is another patch that has a soft dependency on Token.

It has two modes, the old `[node:group]` which provides full access to the delta 0 group attributes. Plus `[node:groups]` which will concatenate all parent groups. To access a particular group label `[node:groups:value:N]` (also `[node:groups:first]`, `[node:groups:last]`)

I see we can do $node->save() in GroupNodeFormStep2::save(), but it just does not feel right.
There must be a way to update the path alias without saving the node (e.g. using PathautoGenerator to get the new alias and then \Drupal::service('path.alias_storage')->save($entity->urlInfo()->getInternalPat‌​h(), $your_alias, $entity->language()->getId())

kristiaanvandeneynde’s picture

There must be a way to update the path alias without saving the node

Completely agree

zerolab’s picture

Here is updated patch that will trigger the path alias generation after GroupContent has saved.

rachel_norfolk’s picture

Status: Needs review » Needs work

Having a pathauto pattern of stories/[node:group]/[node:title] deleting and recreating paths does not currently lead to path aliases being created - they just come out as node/nnnn for me.

rachel_norfolk’s picture

aha! interestingly, stories/[node:group:title]/[node:title] DOES work - which does make sense and probably what I should have chosen. Still, it does show that [node:group] probably should not even be in the list?

rogertcd’s picture

StatusFileSize
new72.85 KB

The patch works well. However, when a node is edited there is an error

Token error

kristiaanvandeneynde’s picture

That relates to this block:

  /** @var \Drupal\group\Entity\GroupContentInterface $group_content */
  $group_content = array_pop($group_content_array);
  $group = $group_content->getGroup();
  $replacements[$tokens['group']] = $group->label();

There is no check whether there is a group key in $tokens.

kristiaanvandeneynde’s picture

Having looked into this patch, it seems to be a really nice addition but I have a few remarks:

  • We're using token_render_array but that function says
    Do not use this function yet. Its API has not been finalized.
  • I would drop the 'groups' token and make the 'group' token the multiple one. We can state that Group requires Token in order to function properly. Having 2 tokens that could do the same thing is just confusing.
  • We're specifying something in gnode.tokens.inc that could be generalized in group.tokens.inc

For the latter point: We could check for installed plugins in group_token_info(), figure out what entity types they are serving and then set the parent groups token for all of those entity types.

Hoe does that sound?

kristiaanvandeneynde’s picture

As for the recalculating the path alias: That part can be removed from the patch again. Turns out we have a lot of issues that require the grouped entity to be re-saved when (un)grouped. See the patch in #2753629-4: Invalidate a node's cache tag when added/removed to/from a group.

rachel_norfolk’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB

I still need to deal with the removal of the token_render_array function but this should at least move it on a little bit. It seems it is only an addition of the gnode.tokens.inc file now.

Oh - I need to get a few things out into a generic group.tokens.inc, too.

rachel_norfolk’s picture

Status: Needs review » Needs work

arrrgh - this is wrong. It is no longer producing results. I though it was hence the upload.

rachel_norfolk’s picture

StatusFileSize
new2.44 KB

Right - let me add back in the group token for the time being, as it was, but lose the need to specially rebuild url aliases and get rid of that error above in #16.

The question I need to answer next, is why can I do [node:group:label][node:title] but not do the same thing with groups taken? How exactly should I write it?

rachel_norfolk’s picture

I'm also think we should have a [node:group:path] token, that provides the aliased path to the group (rather than the full url), seeing as the most likely use of the [node:group:***] operation is to get a path for the group.

ericras’s picture

Here's an addition to #22 that makes the URL chained so that we can do [node:group:url:path].

akalata’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: group_add-node-group-tokens-2774827-24.patch, failed testing.

maxilein’s picture

Under the available tokens there is [group_content:gid:entity:title] isn't that what you are looking for?

Or is this issue about adding tokens to "regular" nodes which are not declared as "group content"?

maxilein’s picture

Tested the latest failing patch #26 - works fine for me!
Thanks.

maxilein’s picture

There exists a module that creates post save events... it may be of use... https://www.drupal.org/project/hook_post_action

maxilein’s picture

I am not sure whether this should be here:

Creating a node using https://www.drupal.org/project/auto_entitylabel

[node:group:id] [node:group:label]

Causes 2 errors:

Drupal\Core\Database\InvalidQueryException: Query condition 'group_content_field_data.entity_id IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 71 of /../core/lib/Drupal/Core/Database/Query/Condition.php).

Drupal\Core\Entity\EntityStorageException: Query condition 'group_content_field_data.entity_id IN ()' cannot be empty. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 770 of /../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

(I also reported this here https://www.drupal.org/node/2778111#comment-12021888, because I do not know what the cause may be.)

kristiaanvandeneynde’s picture

Re #30: Please don't post the same error in two separate issues. If unsure, post it in one and link to it from the other.

[node:group] is unsupported in Group 8, it's what this issue is trying to add. So your setup would obviously fail unless you applied a working patch from this issue.

maxilein’s picture

Ok. I will post in the other then.

kristiaanvandeneynde’s picture

+  $group_content_array = GroupContent::loadByEntity($data['node']);
+  if (empty($group_content_array)) {
+    return [];
+  }

This does not check whether the node has been saved before, potentially causing a crash in the group content storage handler. See stack trace in this comment. I might fix that in the storage handler.

recrit’s picture

mxt’s picture

What's the status of this issue?

I tried patch in #24 and works very well.

orbmantell’s picture

Updating #24 to address #33

berdir’s picture

Status: Needs work » Needs review

Tested this as well in our project and it works. I think performance is a bit a problem, because now it *always* loads the group content, even if there are not actually any tokens that need it. It will result in some duplicated content due to the groups/group thing, but I would suggest to move loading of the group inside the if statements about actually calling out to process the nested tokens.

Also, tests for this would be good, I'll see if we can do something about that.

Setting to needs review so that testbot runs against #37.

Status: Needs review » Needs work

The last submitted patch, 36: group_add-node-group-tokens-2774827-36.patch, failed testing. View results

berdir’s picture

Ah, this seems to be actually failing on existing tests, so it should not be too hard to extend that with a node and generating the group tokens through that?

One more thing. Right now, the groups token is type array, which means you only get a bunch of generic array token suggestions in the UI. Array kind of means a list of strings, you can't do something like node:groups:first:name or so, as token isn't generic enough to be able to know what is in the array and pass it along correctly.

One option would be to do it like token.module does for multi-cardinality field tokens, where it defines a custom token type for each field type in field_token_info_alter(), and then define that as as something that has an index and each element is again token type group.

Or if we don't have a use case for that, we could just drop it for now?

floydm’s picture

The translations of the parent group aren't being picked up. The language of the parent should match the language of the child, no?

This is 36 applied against RC2 with the loading of the parent group translation added. In my testing this appears to solve the problem of generating path aliases in the appropriate language when both the parent and the child have translations.

geek-merlin’s picture

Category: Support request » Feature request
StatusFileSize
new690 bytes
new5.15 KB

Wrapped getTranslation() in hasTranslation() to avoid WSOD.

bsnodgrass’s picture

Patch on #40 was working with pathauto-8.x-1.2 and Drupal 8.6.3, upgrade core to 8.6.5 and pathauto-8.x-1.3

We got the following error, which was fixed by the patch identified in this Pathauto issue https://www.drupal.org/project/pathauto/issues/3003373

Error: Call to undefined method Drupal\pathauto\VerboseMessenger::addError() in Drupal\pathauto\PathautoGenerator->updateEntityAlias() (line 352 of /modules/pathauto/src/PathautoGenerator.php) #0

robertragas’s picture

I don't get the error as described above and locally i'm running core 8.6.7 and pathauto 8.x-1.3 so patch is working quite well for me.

Did wrote some additional code that updates the aliases of the content under a group when the main group alias has changed.

mrpauldriver’s picture

What is the latest on this?

I am using the latest dev version of Group. Drupal core 8.7.0 and Pathauto 8.x-1.4

So far I am having no success with the any of the group content tokens, nor with this patch or anything else. It feels like I didn't get sent the memo :-)

willabby’s picture

@MrPaulDriver the patch from #41 works for me with Drupal 8.7.0, Group 8.x-1.0-rc2, and Pathauto 8.x-1.4

mrpauldriver’s picture

@wiilabby please can you say which tokens you are using?

mrpauldriver’s picture

I was not getting anywhere with generating URL alias patterns. After selecting what seemed like the correct tokens nothing would happen when updating aliases.

It turned out that was selecting Group Content for the pattern type when I should have been choosing Content instead. Silly me.

Is there a logical reason for why Group Content was the wrong pattern type for group content?

bubbaF377’s picture

Category: Feature request » Support request
Status: Needs work » Active
Issue tags: -Dublin2016

Drupal 8.7, Pathauto 8.x-1.4.

I applied the patch 41 and am able to create tokens for valid routes. However, the address bar results are not what i was expecting.

Given URL alias = /[node:group:title]/[node:title]

expected: 'mysite/groupTitle/nodeTitle'
observed: 'mysite//%5Bnode%3Agroup%3Atitle%5D/%5Bnode%3Atitle%5D'

Did I do something wrong? If the observed value is correct for this patch, is anyone aware of a patch that will give me the expected results?

patrick.thurmond@gmail.com’s picture

I was able to apply the #41 patch via composer. Just apply it and clear all Drupal cache. It starts working immediately.

I am currently running Groups version "1.0.0-rc3", Pathauto version "1.4.0", and Drupal version "8.7.2". I would love to see this merged into code.

patrick.thurmond@gmail.com’s picture

@bubbaF377: Here are some examples as to what I used on a project. Bear in mind that the order of the patterns relative to your other patterns can cause it to skip the pattern you want.

For Articles in a group:
/[node:group:title]/news/[node:title]

Right after that I have this for articles not in a group:
/news/[node:title]

Clients in a group:
/[node:group:title]/clients/[node:title]

Clients not in group:
/clients/[node:title]

joshuami’s picture

Added a relationship to #2813405. That patch includes a [node:groups] token that could use some of the thinking from this patch.

One key issue is that a content entity can have multiple group content entities that relate it to multiple groups. So there really needs to be some notion of weight to the group content entities so that they can be compared to each other on a given content entity.

Maybe a set of tokens like:

[node:groups:0:title]
[node:groups:0:url.path]
[node:groups:1:title]
[node:groups:1:url.path]

This would make it possible to target a "primary" group as well as additional groups for things like news content that needed to get its primary group's path alias but still have relationships to other groups for appearing in the news lists for those groups.

joshuami’s picture

jdearie’s picture

I was able to apply the #41 patch via composer. Applied it and clear all Drupal cache. It worked right away. Thank you!

I am currently running Groups version "1.0-rc4", Pathauto version "1.4", and Drupal version "8.7.6". I too would love to see this merged into code.

patrick.thurmond@gmail.com’s picture

So I am not sure why this wouldn't be merged in at this point. People are having success with it.

Thoughts? It has been 3 months and the needle hasn't moved.

kristiaanvandeneynde’s picture

So I am not sure why this wouldn't be merged in at this point. People are having success with it.

Thoughts? It has been 3 months and the needle hasn't moved.

A massive backlog due to me being the only active maintainer, having limited resources and having bigger fish to fry over the last few months. I'll try to go over all outstanding feature/support requests when I finally have the time to tag a full release.

lobsterr’s picture

Status: Active » Needs review
gatorjoe’s picture

I applied patch #41 and had no results. Patch #7 from #2916907 did solve this issue for me (however, I think the implementation might need some work.)

mobius_time’s picture

Patch in #40 worked for me.

Edited composer.json to add this to the extras section:

        "patches": {
            "drupal/group": {
                "Get token of node's parent group; https://www.drupal.org/project/group/issues/2774827 #40": "https://www.drupal.org/files/issues/2018-10-29/group_add-node-group-tokens-2774827-40.patch"
            }
        }

Then ran composer update.

Went to pathauto patterns (/admin/config/search/path/patterns), clicked Add pattern, selected "Content" for pattern type, specified the applicable content type. [node:group] was now available in tokens.

r-mo’s picture

StatusFileSize
new5.01 KB

Added a lookup for the group from the group route context to fix missing node:group tokens when creating a new entity and fixed the coding standards warnings.

Status: Needs review » Needs work

The last submitted patch, 59: group-gnode_tokens-2774827-59.patch, failed testing. View results

r-mo’s picture

StatusFileSize
new6.41 KB

Fixing test. Still need test adding for node:group tokens.

r-mo’s picture

StatusFileSize
new6.39 KB
kyberman’s picture

Thank you very much! I can confirm patch #62 works nicely.

jonathan_hunt’s picture

Thanks for the patch. Token [node:group:title] working for me via patch #62.

lobsterr’s picture

Status: Needs work » Reviewed & tested by the community

Tested. it works

adriancotter’s picture

With recent changes, #62 seems to no longer be functioning in composer. This might be merely because of line number changes. Anyone else having issues?

karlshea’s picture

Sometimes a composer install after a "failed" patch will do it. I think it gets confused.

adriancotter’s picture

Thanks much @KarlShea. Composer was indeed confused, but eventually got it working.

tvalimaa’s picture

Thank you. Patch #62 works fine with Group module 1.2 version and composer.

edward_nurelm’s picture

Patch #62 does not work. This is becoming quite a frustrating issue for me with this group module and we've committed to using this on a very large project that could really utilize pathauto.

kekkis’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.13 KB

Adding rerolled patch, this applies to 8.x-1.3 and (current) 8.x-1.x branch.

Another question is whether this is a valuable reroll; I have not tested it yet myself.

safetypin’s picture

StatusFileSize
new3.13 KB

After clicking through a few pages of a site running group, I've discovered a call to a deprecated function - Group::urlInfo(). This is inherited via EntityInterface, and needs to be replaced by Group::toUrl(). I'm a little confused by how small this patch is now, but the patch from #62 applies cleanly to 8.x-1.3 tag, but with much fewer changes resulting. I will test the results, but I have confirmed that this method rename works if you're trying to update to D9.

berdir’s picture

Status: Needs review » Needs work

Both #71 and #72 are missing the new file that was in the previous patches and are incomplete.

Also, it would make sense to keep the url case in the current position and just fix the cacheability metadata thing (and do that for edit-url too).

kekkis’s picture

StatusFileSize
new6.39 KB

Sorry, the missing new file was my bad. Here's #72 with the new tokens.inc included. No other changes.

bessonweb’s picture

#74 Work for me.

  • Drupal 8.9.9
  • Group 8.x-1.3
  • Pathauto 8.x-1.8

Thanks!

jordik’s picture

Status: Needs work » Needs review
rzb’s picture

StatusFileSize
new6.5 KB

Attached is the edited patch to fix an issue on revisions display, where the $data['node'] can be the id of the node instead of the Node entity.

berdir’s picture

+++ b/modules/gnode/gnode.tokens.inc
@@ -0,0 +1,114 @@
+
+  if (is_numeric($data['node'])) {
+    $data['node'] = Node::load($data['node']);
+  }
+
+  if (!$data['node']->id()) {

You should include an interdiff when existing patches.

And this change should not be necessary, node must be a node object, not an ID. It is the responsibility of the code calling token replace to ensure it is passing node objects in. See #2730631: Upcast node and node_revision parameters of node revision routes, my comment #150 and others from me that explain that.

johnlutz’s picture

#74 Work for me.

Drupal 8.9.15
Group 8.x-1.3
Pathauto 8.x-1.8

oliver huynh’s picture

#77 works fine with me

rudy.barrett’s picture

Has there been any progress with making this patch compatible with Group 8.x-1.4? I did not see any commits of this to @dev or 1.4. I'm still unable to get Pathauto to fire when creating group content nodes.

camslice’s picture

#77 works for me. Just what I needed! Thanks for everyone's efforts

Drupal   9.2.4
Group    8.x-1.4
Pathauto 8.x-1.8
jeffm2001’s picture

Just a flag that I ran into a performance issue with this patch. Admittedly, it's probably a bit of an edge case.

On my site:
- A single node can be associated with many groups
- There are a lot of fields on groups, so loading is relatively expensive

The performance issue came up where, on any node token replace gnode_tokens is loading all of the group_content's for the node and all the groups, even if the token being replaced doesn't even use groups or group.

It turns out that I don't really need the functionality in this patch anymore, so just flagging here for now, but I would recommend adding checks for which token types are being replaced before doing the work of loading the groups.

bessonweb’s picture

Component: Group (group) » Code
Status: Needs review » Reviewed & tested by the community

Hi,

It's would be very nice to finish this.

Someone can?

dianacastillo’s picture

what about for media? can the same thing be done to get the title of the medias parent group? i see there is an issue for this .https://www.drupal.org/project/groupmedia/issues/3008087

cainaru’s picture

I have not had time to test this, but I would imagine anything similar for groupmedia as mentioned in https://www.drupal.org/project/group/issues/2774827#comment-14437893 should be added to that particular contrib module.

Anonymous’s picture

#77 works like a charm. Thanks all!

Drupal 9.4.5
Group 8.x-1.5
Pathauto 8.x-1.11

ytsuhako’s picture

#77 works fine. thank you.

Drupal 9.4.5
Group 8.x-1.5
Pathauto 8.x-1.11

dipanjan.kundu’s picture

Version: 8.x-1.x-dev » 8.x-1.5
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.15 KB

Changed $group->urlInfo() to $group->toUrl() in group.tokens.inc

thatguy’s picture

Re-rolled patch #89 for the 3.0.x-dev version

Status: Needs review » Needs work

The last submitted patch, 90: group-2774827-90-gnode-tokens-updated-for-3.0.x-dev.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

thatguy’s picture

Status: Needs work » Needs review
kroh’s picture

StatusFileSize
new4.63 KB

Re-rolled patch from #90 to work with 2.0.x

Status: Needs review » Needs work

The last submitted patch, 93: group-2774827-93.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rteijeiro’s picture

I'm experiencing an issue with this. After applying the patch in #90, I create new content in a group and it seems the tokens in [node:group:*] are empty just when the content is created. If I try to recreate the path aliases, then it works. Not sure if the issue is caused for some misconfiguration but I'm still investigating.

Sharing this if someone else experienced the same or not.

rteijeiro’s picture

I solved the issue in #95 forcing the path alias to be created in `hook_entity_presave` only for newly created entities. I'll test if this is just an issue in my environment or if I can reproduce it in the latest versions of Drupal and the contrib modules. In the meantime I'll leave the code below if someone experiences the same issue:

if ($entity->isNew()) {
      $entity->path = \Drupal::service('pathauto.generator')->updateEntityAlias($entity, 'insert');
}
realityloop’s picture

#90 working on 3.x

caesius’s picture

Version: 8.x-1.5 » 3.0.x-dev

I assume from the comments and patches this applies up to 3.x, so updating the version for visibility.

jaydarnell’s picture

I've tested the patch from #90 on a few sites now and it seems to work really well.

adriancotter’s picture

I have an error with #93 after I upgraded to 2.2.2, I am getting:
ArgumentCountError: Too few arguments to function Drupal\group\Access\GroupPermissionsHashGenerator::__construct(), 3 passed in ...web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 5 expected in Drupal\group\Access\GroupPermissionsHashGenerator->__construct() (line 70 of modules/contrib/group/src/Access/GroupPermissionsHashGenerator.php).

Any admin page throws an error. Group pages and related nodes also get the error. But non-group content is still viewable on the front end.

Steps to reproduce

We are still on Drupal 9.5.11
I got this after upgrading my Group module from 2.2.0 to 2.2.2
I was able to update to 2.2.1 ok

I decided to check if this patch might have an impact, when I saw the Token functions in the stack trace.
I don't immediately see where the patch might need to be tweaked.

When I took out the patch the errors went away.

Drupal\group\Access\GroupPermissionsHashGenerator->__construct(Object, Object, Object) (Line: 259)
Drupal\Component\DependencyInjection\Container->createService(Array, 'group_permission.hash_generator') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('group_permission.hash_generator', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'cache_context.user.group_permissions') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('cache_context.user.group_permissions') (Line: 223)
Drupal\Core\Cache\Context\CacheContextsManager->getService('user.group_permissions') (Line: 185)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 111)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 317)
Drupal\Core\Render\RenderCache->createCacheID(Array) (Line: 66)
Drupal\Core\Render\RenderCache->get(Array) (Line: 109)
Drupal\Core\Render\PlaceholderingRenderCache->get(Array) (Line: 77)
Drupal\Core\Render\RenderCache->get(Array) (Line: 109)
Drupal\Core\Render\PlaceholderingRenderCache->get(Array) (Line: 273)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 446)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 43)
__TwigTemplate_f60975c3bcef63585ca1e008bb6405ed->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/contrib/seven/templates/page.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 86)
__TwigTemplate_18e80ba8011e325cf036296dbb23f15b->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/contrib/seven/templates/classy/layout/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 163)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 44)
Drupal\redirect_after_login\RedirectMiddleware->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

karlshea’s picture

Category: Support request » Feature request
Status: Needs work » Needs review

Created MRs for both 3.x and 2.x from the latest patches.

slydevil’s picture

Applied the patch for the 2.x branch and it works well. Not moving to RTBC since I did not try the 3x branch.

vamirbekyan’s picture

pls note that for group v3.x in the subject patch the GroupContent is replaced with GroupRelationship

dave.weiner’s picture

This patch looks exactly like what I need, but I'm new to the group module, and I'm not understanding how this patch works. I've patched the group module (3.x) with the diff from the MR and it applies cleanly, but I'm still not seeing any group tokens when I select Content as the pattern type in pathauto.

Can someone please explain it to me like I'm a 1st grader? :)

karlshea’s picture

You should be able to use [node:group] tokens. I'm still using Group 2.x (MR 157), if you're on 3.x (MR 156) the MR might be wrong, but I haven't been able to test it.

dave.weiner’s picture

Karlshea, I must be missing something. I'm running version 3.2.2, the patch from MR 156 applied cleanly, and I also have group_content_menu v3.0.3 and group_context_path_prefix v1.1.2 installed. When I go into the Pathauto configuration and select content for the pattern type, I don't have a [node:group] token in the list of available tokens. Selecting group or group relationship, there are no node tokens in the list of available tokens. What am I missing? Is there a configuration option I'm not setting?

karlshea’s picture

Is node one of the available types of content in one of your groups? Tried clearing caches? Otherwise you might have to debug yourself or wait for someone running Group 3.x to chime in, I'm not sure.

dave.weiner’s picture

I found the issue -- I don't know if this was part of it, but disabled group_contenxt_path_prefix and then enabled it again. It also looks like I was hitting the pathauto configuration page inside of the group. Once I did it at the top level, I had the token available. I had to delete an existing pattern for article and basic page, and now it's working how I expect it to. Thanks for the help!

mandclu’s picture

Status: Needs review » Reviewed & tested by the community

This is exactly what I was looking for. After applying the changes in MR!156 I was able to use a node token that references the parent group. Thanks to everyone whose work made this possible!

dalemoore’s picture

Like @mandclu, I've tested the MR!156 in Group 3 and it works! Though I only tested it on content that belongs to one group. Next up: to see if I can create a path based on a Group Content Menu...

rachel_norfolk’s picture

updating my attribution

rachel_norfolk’s picture

and trying again - it’s persistent today ;-)

dave.weiner’s picture

Status: Reviewed & tested by the community » Needs review

MR 156 is working for me as well. Any idea when this might be merged in?

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community

I’m going to assume you didn’t mean to change the status, Dave.weiner?

edvanleeuwen’s picture

I am trying to patch this to the latest version (3.3.4). I now get:

Error: Class "Drupal\group\Entity\GroupContent" not found in gnode_tokens() (line 59 of /home/myuser/domains/mydomain/public_html/web/modules/contrib/group/modules/gnode/gnode.tokens.inc).

Edit: my bad. Patched a 3.x version with the #41 which was displayed at the top and not the #93 in the comments.

tim-diels’s picture

Assigned: Unassigned » tim-diels
Status: Reviewed & tested by the community » Needs work

Hiding the patches files as the current approach is to use MRs. There are 2 MRs that seem to solve the issue and patch from #41 looks the same as MR157.

I've tested MR156 and that provided the tokens I was looking for.

But it seems no pipelines are running? I'll rebase and see if that triggers the pipeline.

tim-diels’s picture

Version: 3.0.x-dev » 3.3.x-dev
Assigned: tim-diels » Unassigned

I rebased both MRs but for the 2.x I rebased on the 2.3.x so that MR needs to be changed to 2.3.x instead of 2.2.x. I'm not able to do this, anyone else have this option?

tim-diels’s picture

Also with the pipelines running now, there is more work to do.

dhaval_panara’s picture

@tim-diels : Due recent changes "https://git.drupalcode.org/project/group/-/merge_requests/157.patch is started to getting failed on our installed group module 2.3.1.

tim-diels’s picture

@dhaval_panara please do not use mr diff links in your workflow. This is very dangerous! Please read https://github.com/cweagans/composer-patches/issues/347

slydevil changed the visibility of the branch 2774827-2-get-a-token to hidden.

slydevil changed the visibility of the branch 2774827-2-get-a-token to active.

slydevil’s picture

I've created a new MR which isolates the changes from the 2.2.x branch for the 2.3.x branch.

bryanmanalo’s picture

StatusFileSize
new4.05 KB

Since MR pathces are dangerous as mentioned, is the recommended way for now to create a patch on DO based on an existing MR?

Adding a patch for 2.3.1 MR 232

evilehk’s picture

Status: Needs work » Needs review
StatusFileSize
new5.45 KB

Rebased against 3.3.x, after commit `aa30540` that refactors how tokens are implement with the cool modern way!
Patch supersedes earlier patches/MRs that contained unrelated scope. This implementation is intentionally minimal and focused only on exposing a node's parent group as a token. Kernel tests included.

evilehk’s picture

This patch builds on the patch from #128, and handles ungrouped nodes and allows test `NodeGroupTokenReplaceTest` to pass.

karlshea’s picture

Should we organize a celebration for this issue's 10th birthday? It's coming up soon!