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.

Issue fork pathauto-3210298

Command icon 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:

Comments

marios anagnostopoulos’s picture

StatusFileSize
new2.5 KB

DeaOm made their first commit to this issue’s fork.

deaom’s picture

Status: Active » Needs review

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

Status: Needs review » Needs work

The last submitted patch, 3: pathauto_allow_multiple_separator.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

deaom’s picture

Status: Needs work » Needs review

mably made their first commit to this issue’s fork.

mably changed the visibility of the branch 8.x-1.x to hidden.

mably’s picture

Pathauto: Preserve consecutive separators feature

These three commits introduce and refine a new Pathauto setting that controls
whether consecutive separator characters (e.g. foo--bar) are
collapsed into a single one (foo-bar) or left as-is.

Commit 1: 34955c9 — Adds option to ignore multiple separator stripping

Introduces the core feature: a new preserve_consecutive_separators
setting (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.

  • AliasCleaner.php: wraps the duplicate-separator collapsing
    regex in a conditional check against the new setting.
  • PathautoSettingsForm.php: adds a checkbox to the settings
    form so site administrators can toggle the behavior.
  • PathautoSettingsFormWebTest.php: updates the test to
    include the new form field in default values and assertions.

Commit 2: 2fe9516 — Added missing schema for multiple separator

Adds the configuration schema definition for the new setting so that Drupal's
config system can properly validate it.

  • pathauto.schema.yml: declares
    preserve_consecutive_separators as a boolean.

Commit 3: 210e7af — Rename and harden the feature

Renames allow_multiple_separator to
preserve_consecutive_separators for clarity, adds the default value
to install config, provides an update hook, and fixes a bug where enabling the
setting would also prevent duplicate slashes from being collapsed.

  • config/install/pathauto.settings.yml: adds the explicit
    default (FALSE).
  • pathauto.install: adds pathauto_update_10001()
    to initialize the setting for existing sites.
  • AliasCleaner.php:
    • Duplicate slashes (//) are now always collapsed regardless
      of the preserve setting ($separator === '/' check).
    • The slash-cleanup regex now uses $seppattern+ instead of
      $seppattern to properly strip multiple consecutive separators
      adjacent to slashes (e.g. foo/--/bar
      foo/bar).
  • PathautoKernelTest.php: adds
    testCleanAliasWithPreserveConsecutiveSeparators() covering
    preserved separators in path segments, slash collapsing, and separator
    cleanup around slashes.
mably’s picture

Assigned: Unassigned » berdir