Problem/Motivation
In our project, for SEO reasons, we want to create urls that look like ../first-part--second-part--third--fourth/..
In other words we want to have the "-" character as a word separator and double dash to separate semantic concepts (In our case taxonomy terms that are referenced in our entity).
So we created a custom token for it, but during the token generation the additional consecutive instances of the word separator are cleaned by the cleanAlias function.
Of the top of my head I can not think of a good reason why this would be enforced, but then again I might be wrong. In any case I provide a patch, that creates a checkbox option to allow bypassing this.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | pathauto_allow_multiple_separator.patch | 2.5 KB | marios anagnostopoulos |
Issue fork pathauto-3210298
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:
- 3210298-multiple-separator
changes, plain diff MR !145
- 8.x-1.x
changes, plain diff MR !3
Comments
Comment #3
marios anagnostopoulos commentedComment #5
deaom commentedWill mark this as needs review if somebody else also wants to test it out, but the patch does apply and it works as described. If the "Allow duplicate separator" is checked, the alias does not remove the second dash, if it's not checked it works as before by removing duplicated dash. Maybe good to note is that because spaces are replaced by dash it can happen that three or more dashes will be present in the alias. The test is failing because of the missing schema, so I added that and it should now pass.
Comment #7
deaom commentedComment #11
mably commentedPathauto: Preserve consecutive separators feature
These three commits introduce and refine a new Pathauto setting that controls
whether consecutive separator characters (e.g.
foo--bar) arecollapsed into a single one (
foo-bar) or left as-is.Commit 1:
34955c9— Adds option to ignore multiple separator strippingIntroduces the core feature: a new
preserve_consecutive_separatorssetting (originally named
allow_multiple_separator). When enabled,Pathauto no longer collapses consecutive separators into one. This is useful when
separators carry semantic meaning in the alias.
regex in a conditional check against the new setting.
form so site administrators can toggle the behavior.
include the new form field in default values and assertions.
Commit 2:
2fe9516— Added missing schema for multiple separatorAdds the configuration schema definition for the new setting so that Drupal's
config system can properly validate it.
preserve_consecutive_separatorsas a boolean.Commit 3:
210e7af— Rename and harden the featureRenames
allow_multiple_separatortopreserve_consecutive_separatorsfor clarity, adds the default valueto install config, provides an update hook, and fixes a bug where enabling the
setting would also prevent duplicate slashes from being collapsed.
default (
FALSE).pathauto_update_10001()to initialize the setting for existing sites.
//) are now always collapsed regardlessof the preserve setting (
$separator === '/'check).$seppattern+instead of$seppatternto properly strip multiple consecutive separatorsadjacent to slashes (e.g.
foo/--/bar→foo/bar).testCleanAliasWithPreserveConsecutiveSeparators()coveringpreserved separators in path segments, slash collapsing, and separator
cleanup around slashes.
Comment #12
mably commented