3

I have a custom token that gets the path value from a JSON field. The JSON field stores the path like this (in the database, the slashes are escaped, but I'm showing an unescaped example here):

{ "path": "a/b/c" }

Every node contains this JSON field, so I made a custom token, [mymodule:json_path].

I then set this token as the path for nodes on the PathAuto patterns page (/admin/config/search/path/patterns).

However, PathAuto is stripping the slashes, so when I save a node, I get the path abc when I want a/b/c.

Elsewhere, when I use the token, I get the value with unescaped slashes as expected (for example, a/b/c); I know this because if I set a metatag on the node to the token, the expected value appears.

Also, if I disable Generate automatic URL alias and manually set the path to /a/b/c, then I get the expected path of /a/b/c.

So, how can I get PathAuto not to remove the slashes?

2 Answers 2

2

This can be done through the UI, at /admin/config/search/path/settings.

Scroll down to "Punctuation" at the bottom, expand it, find the Slash (/) option near the end of the list, and set it to something other than Remove.

enter image description here

1
  • If needed, you can fine-tune the behavior with hook_pathauto_alias_alter().
    – jlstrecker
    Aug 12, 2023 at 3:08
1

In admin/config/search/path/settings, add your custom token to Safe Tokens.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.