Hi,
if the slash is removed in the punctuation configuration the token [term:parents:join-path] does not join terms properly, because the "/" is stripped after url generation.

Example:
with 8.x-1.2 --> /temi/agricoltura/agroindustria-ricerca-e-innovazione
with 8.x-1.3 --> /temiagricoltura/agroindustria-ricerca-e-innovazione

Thanks

Comments

charly71 created an issue. See original summary.

njim’s picture

I had a similar issue and was able to fix it by adding a 'safe token' on this admin interface to avoid certain types of token from being processed by the AliasCleaner. Adding 'path' to the list of safe tokens will ensure that any paths being passed as a token will not enter this sanitizing process. Looking back at the changelog, past safe tokens that were hardcoded in the module included: path|alias|url|url-brief

Alternatively, you can change the punctation settings for pathauto. Visit the administrative settings page for the pauthauto module (/admin/config/search/path/settings) and navigate to the 'Punctuation' fieldset. Change the settings for "Slashes" from "Remove" to "No Action (Do Not Replace)". Be caution that your site is ready for this setting-change as slashes brought in by text fields will cary through to the URL.

I do not know the scope of recent changes to the pathauto module; I am unsure if this is new functionality or if one of the helper classes is simply using these settings differently.

jnicola’s picture

I just started running into this myself. Never had this apply to anything else we've had before this for months, and then suddenly it's a thing.

The punctuation method above seems to work for us, but does require regenerating all aliases.

Unsure if there are any implications from all of this.

njim’s picture

I'm posting a follow up because I've received several messages on previous comment. This problem started with some changes in Pathauto 8.x-1.3 when the 'safe tokens' were moved from hardcoded references in the module to the modules 'Settings' page. This mechanism filters/replaces punctuation in tokens according to your site's settings. But some tokens, like paths and aliases, may need symbol like slashes.

The module should have prevented this issue for me
The pathauto contributors accounted for the problems that I had by including an update hook in pathauto.install. But I'm not sure why this didn't fire for me. Perhaps there was a problem with the order of operations of my updates and configuration tasks. Also not sure why 'alias' is included twice.

/**
 * Initialize the new safe tokens setting.
 */
function pathauto_update_8107() {

  $safe_tokens = [
    'alias',
    'alias',
    'path',
    'join-path',
    'login-url',
    'url',
    'url-brief',
  ];

  \Drupal::configFactory()->getEditable('pathauto.settings')
    ->set('safe_tokens', $safe_tokens)
    ->save();
}

A manual fix is easy to implement
If you are having similar problems, the safe token patterns can be manually set on the module's settings page (/admin/config/search/path/settings). For the 'Safe Tokens' field, add the following values to match what is in the install hook: alias, path, join-path, login-url, url, url-brief

jnicola’s picture

It would appear there is more going on than meets the eye. Writing a behat test to validate that this is infact the solution, and here's what happens when I just make the slash replacement above!

Scenario: Group paths can have multiple slashes and it inherits without issue into group content.
    Given I am logged in as a user with the "administrator" role
    When I am at "group/add/org_default_group"
    Then I fill in "Group Title" with "BEHAT -- Test group aliasing - DELETE"
    And I fill in "URL alias" with "/oh-snap-this/works/get-outta-here"
    And I press the "Create ORG Default Group and complete your membership" button
    And I press the "Save group and membership" button
    Then I should see the text "ORG Default Group BEHAT -- Test group aliasing - DELETE has been created." in the "messages" region
    And print last response
    Then I click "Create Basic Page" in the "group_controls" region
    And I fill in "Title" with "url alias testing"
    And I press the "Save" button
    Then I fill in "Description" with "This description field thing is a bit of a nuisnace but hey man sometimes you just gotta write out a really long description because people gotta FIND this stuff ammiright?"
    And I press the "Create content in BEHAT -- Test group aliasing - DELETE" button
    Then I should see the text "Basic Page url alias testing has been created." in the "messages" region
    And print current URL
    Then the current url should contain "oh-snap/works/get-outta-here/url-alias-testing"

What response do I get?

http://web/oh-snap/works/get-outta-here/url-alias-testing

For some reason the second bit of text after the dash is being stripped out as well?

njim’s picture

StatusFileSize
new106.43 KB

@jnicola while my site is structured differently, I can reproduce the issue you are having. My solution above applies to my site, but unsure if it will work for you needs.

I suspect that the url from your group is being passed to the basic page as a token. Then tokens are filtered and altered through several settings. For my site, the "Strings to Remove" field would remove the word "this" when building url values. This feature is useful when URLs are being generated from another content field such as the node's title field and we want to remove filler words from the autogenerated path.

For my site, the page uses a [node:field_parent:entity:url:path] token to help build the url for the child page. This exact token name is likely unique to my site, but your site may have similar logic. The pattern for the child page was created in the pathauto 'Patterns' admin interface. (/admin/config/search/path/patterns).

I need to make sure that my path token does not get altered by the "Strings to Remove" logic. So I added path to the "Safe Tokens" field and it started to work again. I hope this helps. If not, please let us know what you find out.
The safe tokens field on the pathauto settings include path as a token type to skip when filtering.

jnicola’s picture

It should be noted that is is for automatic paths that are built using others automatically aliased paths. I bet this somewhat less common but not rare situation was perhaps not considered.

Any objections to updating and broadening the title?

websiteworkspace’s picture

@nJim

Are you sure your example isn't a typo?

---never mind---

After some testing, your example works!

The problem is that the token list generate at {site}/admin/help/token on a D8 Drupal site does not include this construct in the list!

I even tested this with D8 Commerce 2.x products and it works with those entities as well!!

After quite a long time searching for a solution for D8 commerce products, the construct below is the solution!

The construct below even works with a hierarchy or product categories.


[commerce_product:field_taxo_term_prod_category:entity:url:path]/[commerce_product:title]

You can see the results of implementing the construct above, in action at the following link, whose URL was generated with the token construct above!

(what a relief!!!!!)

https://dc2xdemo.websitework.space/products/category001/category001001/c...

---

(your example)

[node:field_parent:entity:url:path]

Where field parent is apparently a taxonomy term reference?

I looked/checked for a similar construction on my site and can only find the following - without the :path on the end:


[node:field_taxo_category:entity:url]

The - field_taxo_category - portion is an actual field name, which would vary from site to site.

Would it be correct that if the - [node:field_taxo_category:entity:url:path] - construct exists it would generate a relative URL, while the previous form generates a fully qualified URL?

Would you verify the existence of the [ ... :entity:url:path] token construct?

(actual token set on my site when I checked for the - entity:url:path - construct)

2018-11-21/d8-field-taxo-reference-token-constructs

websiteworkspace’s picture

Where the taxonomy reference field for a taxonomy of node categories, include a hierarchy of categories, is:

field_taxo_category

The following token construct can be used as the pathauto module url pattern to generate the complete URL for the node:


[node:field_taxo_category:entity:url:path]/[node:title]

Even if the category (taxonomy term) is deep in a taxonomy hierarchy, the pattern above will yield a URL containing all the terms in the hierarchy.

rwilson0429’s picture

#9 worked for me even though the entity:url:path token doesn't show up when I browse the available tokens. Thanks websiteworkspace

subson’s picture

So the latest code in cleanTokenValues() with safe_tokens is failing for pathauto latest version vs pathauto 8.x-1.2

<?php

$safe_tokens = "alias|path|join-path|login-url|url|url-brief";
$token = "[node:field_taxonomy_path]";

// pathauto 8.x-1.6 code
if (!preg_match('/(\[|\:)(' . $safe_tokens . ')(:|\]$)/', $token)) {
  echo $token;
}
else {
  echo "else";
}

// It prints the token - [node:field_taxonomy_path] (which is incorrect)

// path auto 8.x-1.2 code
if (!preg_match('/(path|alias|url|url-brief)\]$/', $token)) {
  echo $token;
}
else {
  echo "in else";
}

// It prints the "in else" correctly.

seems like putting the complete field name(field_taxonomy_path) in safe tokens is the solution in our case.

berdir’s picture

Category: Bug report » Support request
Priority: Major » Normal
Status: Active » Fixed
Issue tags: -token, -slash, -Parents

Yes, that was a bugfix, it is expected to match whole token parts, otherwise it matched too much as path or url could appaear anywhere in some other token and it would have not transformered it properly. Unfortunately hit you the other way round.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sic’s picture

i am currently experiencing this also, running 1.8

darktek’s picture

#2 comment related to the punctation settings did the work for me, thx!