Hi,

I am running drupal 8.3.5 and I want to use pathauto for forum and container.

When I create an alias for pattern type forum, I can only choose taxonomy tokens,
there are no tokens for forum.

So I choose : /forum/[term:name]

When i do a bulk generate then the following alias is created for the default general discussion forum :

/forum/general-discussion : /taxonomy/term/1

When I go to my drupal home pages and I select the forum, this alias is not used.
The url that is used is : http://host:port/forum/1

When I create the alias for the forum manually :

/forum/general-discussion : /forum/1

It works when I go to the home page and select the general forum.

Am I missing something or is this a bug ??

Comments

jhmnieuwenhuis created an issue. See original summary.

jhmnieuwenhuis’s picture

Issue summary: View changes
jhmnieuwenhuis’s picture

Issue summary: View changes
newkew’s picture

Hi,
same issue for me with drupal 8.3.7 and last pathauto ~8
pattern : /[term:parent:name]/[term:name]
all alias generated are ok but for /taxonomy/term/2 and not forum/2

lelik1973’s picture

The same problem in drupal 8.6.4

TikaL13’s picture

Having the same issue with the following versions:

"drupal/core": 8.6.9
"drupal/pathauto": 8.x-1.3"
Morbus Iff’s picture

Using 8.6.10, a similar problem is happening for users:

* user/[user:account-name]
* account/[user:display-name]
* morbus/[user:uid]

None of the above work.

Berdir’s picture

that has nothing to do with this. Is the pathauto widget visible or not? If not, there's an issue open where people report problems when the widget is not active, might be that.

Morbus Iff’s picture

Confirmed. Sorry.

maenjuel’s picture

Issue tags: +language

I encountered the same problem. If I let pathauto do the work automatically, the links on /forum don't get converted. It doesn't matter whether I chose taxonomy term or forum as pattern type. However, adding the alias manually does the trick.

Looking at the URL aliases, I realized when pathauto adds the alias automatically, it adds English as the language (even though I haven't enabled any language modules). Adding a link manually just adds none (und in the database) to the language. The column language was not even on the URL aliases page before pathauto created the first alias. So I guess that a language is defined doesn't matter for nodes and their aliases, but /forum seems to be a special case.

maenjuel’s picture

Issue tags: -language

I've looked again this morning, and I don't think it has anything to do with the language. If I chose forum as pattern type, it creates a link for the taxonomy term only (taxonomy/term/X), but not for /forum/X. So, the forum pattern type does exactly the same thing as the taxonomy term pattern type.

I'm not very strong in PHP, so I don't see the problem in the code. I look into the code a bit more, but I'm not sure if I'll be able to get at the bottom of it, tbh :)

MartinMa’s picture

This issue seems to be a problem of communication or documentation. For me too it was not clear, that "forum" in the pathauto pattern menu mean the taxonomy of the forums and not the content type of the forum. You have to set up a pattern extra for the content type of forum.

Maybe "forum categories" in pattern menu and bulk creation menu would be a proper term/description instead of "forum".

If I read the term "forum" for me its the whole forum and not only the categories of the forum!

maenjuel’s picture

I'm not sure we need to rename "forum" to "forum categories". We have different things pathauto needs to take care of with the forum module:
- content type
- taxonomy term
- forum category and container URLs (forum "front-end", to actually browse through the forums)

The first two cases can be easily managed by the normal content type and taxonomy pathauto pattern. So, I'd argue "forum" can remain "forum" in the pathauto pattern menu, since it refers to a special case for the third item in the list above. The bug report doesn't refer to content type or taxonomy term of the forum, but to the URL of the forum view (or "front-end", for the lack of a better term) itself.

brunodbo’s picture

Ran into this as well.

I also noticed that when I go to a forum taxonomy term's alias, I end up on a regular taxonomy page, instead of a forum page. So I wonder if somehow Drupal is not connecting the term and the forum on some level.

As described above, if I hover on a forum link on /admin/structure/forum, I see the unaliased URL in my browser's status bar, instead of the alias, even though the alias is set on the forum's edit form (e.g., /admin/structure/forum/edit/forum/1, which is the same as the forum's term alias).

Jhun Vert’s picture

I encountered similar behavior as described in the original post.
Drupal 8.8.5
Pathauto 8.x-1.6

XTaz’s picture

Same as original post for me too after cleaning caches with:
Drupal 8.8.5
Pathauto 8.x-1.8

DrupalBubb’s picture

Don't choose the forum pattern type, it always creates taxonomy terms. But you can set up the correct path through the mechanism by individualy changing the system path from /taxonomy/term/ to /forum/ for all forum entries.
Is noone able to provide a patch for this easy code change?

brunodbo’s picture

cptX’s picture

Hi, any news about this? The same issue happens in Drupal 9.1.2. I'm unable to make a pattern for forums content types. They just don't work. Any workarounds or suggestions for some automation and not manual editing for every category?

eL’s picture

Drupal 9 and Forum - containers not aliased with pathauto. So same problem here.

DrupalBubb’s picture

C.Riemer’s picture

Hello,

same problem here. Drupal 9.1.8. What is the solution?

Regards.

leisurman’s picture

@brunodbo I see the same thing. I have set the pattern for forum to forums/[term:parent:name]/[term:name]When I am in node edit mode for a container or its child forum, the genrated alias looks correct /container1/forum1. But when I veiw the fourm, the url path looks like this http://mysite/forum/220 Is there a workaround?

ryankavalsky’s picture

This workaround is by no means official, but it's working for us in the meantime. Since Drupal can link to these forums from so many places (menus, breadcrumbs, other forums, taxonomy pages, forum tables, etc), I've had to create a good amount of overrides to get it all covered.

I have a custom module with event subscribers that I've coded to intercept taxonomy requests that are actually for forums, and redirect the request to the appropriate forum page using the desired forum URL.

[custom module]\src\EventSubscriber\SharedEventSubscriber.php:

// Run whenever a request is received
public function SharedRequest(GetResponseEvent $event) {
    // Determine if this request is for a taxonomy term or forum
    $objRoute = \Drupal::routeMatch();
    $strRouteName = $objRoute->getRouteName();
    if ($strRouteName == "entity.taxonomy_term.canonical") {
        // Determine if this request is for a forum
        $objCurrentTerm = $objRoute->getParameter("taxonomy_term");
        $strCurrentVocabulary = $objCurrentTerm->getVocabularyId();
        if ($strCurrentVocabulary == "forums") {
            // Redirect to the appropriate forum page, in order to show the forums formatted as a table
            $intCurrentTermID = $objCurrentTerm->id();
            $strCurrentTermName = $objCurrentTerm->label();
            $strPath = "/forum/" . $intCurrentTermID;
            $response = new \Symfony\Component\HttpFoundation\RedirectResponse($strPath, 308);
            $event->setResponse($response);
        }
    }
    else if ($strRouteName == "forum.page") {
        // Force forum pages to use the forum's alias
        $strInternalPath = \Drupal::service("path.current")->getPath();
        $strCurrentURL = \Drupal::request()->getRequestUri();
        $strAlias = \Drupal::service("path.alias_manager")->getAliasByPath($strInternalPath);
        if ($strAlias != $strCurrentURL) {
            $response = new \Symfony\Component\HttpFoundation\RedirectResponse($strAlias, 308);
            $event->setResponse($response);
        }
    }
}

This custom module also deletes the taxonomy path for forums (/taxonomy/term/xx) and creates the forum path (/forum/xx). It also saves an alternative URL to whatever PathAuto was trying to set in the first place, appending "-taxonomy-alias" to prevent duplicates.

[custom module]\shared.module:

function shared_pathauto_alias_alter(&$alias, array &$context) {
    // Only execute for taxonomy terms that are forums
    if (($context["module"] == "taxonomy") && ($context["bundle"] == "forums")) {
        $strLanguageCode = $context["language"];
        $strTaxonomyPath = $context["source"];
        $intTermID = str_replace("/taxonomy/term/", "", $strTaxonomyPath);
        $strForumPath = "/forum/" . $intTermID;

        // Delete the /taxonomy/term/xx alias
        \Drupal::service("path.alias_storage")->delete(["source" => $strTaxonomyPath]);

        // Create the /forum/xx alias and the alternative /taxonomy/term/xx alias
        \Drupal::service("path.alias_storage")->save($strForumPath, $alias, $strLanguageCode);
        $alias .= "-taxonomy-alias";
    }
}

I also have a custom theme that have overrides for the forum list and forum entity reference fields.

[custom theme]\templates\forum-list.html.twig:

...
<div class="forum__name"><a href="{{ path('forum.page', {'taxonomy_term': child_id}) }}">{{ forum.label }}</a></div>
...

[custom theme]\templates\field-node-taxonomy-forums–forum.html.twig:

...
<a href="{{ path('forum.page', {'taxonomy_term': term_id}) }}">{{ term_name }}</a>
...

I hope this helps in some way!

leisurman’s picture

@ryankavalsky. I could not get it to work. Is there a services.yml file? Is is possible to upload the full code for each file you used?

ryankavalsky’s picture

@leisurman Unfortunately this code is part of a much larger custom module and custom theme that I won't be able to include here. You might have to familiarize yourself with setting up an event subscriber: https://www.drupal.org/docs/creating-custom-modules/subscribe-to-and-dis....

I do have a services.yml file in my solution:

services:
  [module name].event_subscriber:
    class: Drupal\[module name]\EventSubscriber\SharedEventSubscriber
    tags:
      - { name: event_subscriber }

And I also have this code block in SharedEventSubscriber.php:

// Register the event subscriber
public static function getSubscribedEvents() {
	$events[KernelEvents::REQUEST][] = array("SharedRequest", 20);
	return $events;
}
leisurman’s picture

@ryankavalsky. Thank you. I will try again. I noticed @brunodbo #14 above. This is already being worked on #2010132: Canonical taxonomy term link for forum vocabulary is broken. In Drupal 7 there was a Pathauto pattern called Drupal 7 Pattern for 'Pattern for forums and forum containers' And this pattern worked well
[term:vocabulary]/[term:parent:parent:parent:name]/[term:parent:parent:name]/[term:parent:name]/[term:name]
'Pattern for forums and forum containers' is not available in Drupal 8/9.

leisurman’s picture

@ryankavalsky. This patch fixed the forums and forum containers url problem on Drupal 9.2.6. 2010132 Canonical taxonomy term link for forum vocabulary is broken

ryankavalsky’s picture

Thanks @leisurman! I'm still on Drupal 8, though.