Get a token of a node's parent group to create a pathauto pattern

Created on 28 July 2016, almost 9 years ago
Updated 17 February 2023, about 2 years ago

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.

๐Ÿ’ฌ Support request
Status

Needs review

Version

1.5

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States cainaru Norwood, NY, USA

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States kroh San Antonio, TX

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

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

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain rteijeiro

    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.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rteijeiro

    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');
    }
    
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia realityloop

    #90 working on 3.x

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States caesius

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada JayDarnell Guelph, Ontario

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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States adriancotter

    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)
    
  • Merge request !156Patch #90 โ†’ (Open) created by karlshea
  • Merge request !157Patch #93 โ†’ (Open) created by karlshea
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States karlshea Minneapolis ๐Ÿ‡บ๐Ÿ‡ธ

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada slydevil Halifax

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada vamirbekyan Toronto

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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dave.weiner

    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? :)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States karlshea Minneapolis ๐Ÿ‡บ๐Ÿ‡ธ

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dave.weiner

    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?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States karlshea Minneapolis ๐Ÿ‡บ๐Ÿ‡ธ

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dave.weiner

    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!

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada mandclu

    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!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dalemoore

    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...

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    updating my attribution

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

    and trying again - itโ€™s persistent today ;-)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States dave.weiner

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

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom rachel_norfolk UK

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

  • Status changed to RTBC 3 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands edvanleeuwen Waalwijk

    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).

  • Assigned to tim-diels
  • Status changed to Needs work 10 days ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    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.

  • Pipeline finished with Failed
    10 days ago
    Total: 158s
    #485415
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    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. I4m not able to do this, anyone else have this option?

  • Pipeline finished with Failed
    10 days ago
    Total: 159s
    #485416
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

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

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dhaval_panara

    @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.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium tim-diels Belgium ๐Ÿ‡ง๐Ÿ‡ช

    @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

  • Merge request !232updated for 2.3. โ†’ (Open) created by slydevil
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada slydevil Halifax

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada slydevil Halifax

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada slydevil Halifax

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

  • Pipeline finished with Failed
    9 days ago
    Total: 256s
    #486778
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines bryanmanalo

    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

Production build 0.71.5 2024