Hi and thanks for this module,
I have a special use case where I must reproduce aliases from an existing site exactly.
Among other problems, I have to keep the number of spaces, so the number of separators, equal from one site to the other.
For example, the string "This is a special string with two spaces here." should translate to :
this-is-a-special-string-with-two-spaces--here (note the two dashes)
... and not to :
this-is-a-special-string-with-two-spaces-here (one dash only)
I'm using the transliteration module, because french accentuated characters must be managed.
A simple hint to a line I must change in the code would do.
Thanks in advance.
Issue fork pathauto-2218457
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
Comment #1
Countzero commentedI tried to change line 209 in pathauto.inc from
$output = preg_replace('/\s+/', $cache['separator'], $output);to various things like
$output = preg_replace('/\s/', $cache['separator'], $output);or
$output = str_replace(' ', $cache['separator'], $output);... but it didn't change anything. I guess spaces are replaced in some other place, but can't find where as of now.
Comment #2
dave reidThis isn't a very good fit for using Pathauto - why not just manually set aliases for your content if you need an exact match?
Comment #3
Countzero commentedBecause I have tenths of thousands of pages which will turn into nodes when migrated.
I think Pathauto is a blessing in this case. It's just the spaces to space thing which bugs me.
Comment #4
Countzero commentedLet me try to explain better what I'm trying to do :
- pathauto is perfect for my use case, because of the bulk update feature which lets me update my nodes' paths in minutes.
- The only thing I want is changing the default behaviour, which replaces multiple spaces with only one.
- For my purpose, I'll use a modified version of pathauto, just for the time of the migration.
- I don't understand why the modification I mentioned above doesn't change the behaviour of the module.
So, if someone could just point me to the correct lines of code in the module which I should modify to achieve this (or explain the basic workflow used, or what I miss), it would be a perfect solution for me.
Thanks in advance
Comment #5
kksandr commentedComment #7
kksandr commentedI came across this request several times, maybe someone else needs it, so I suggest introducing an option for this.
Comment #8
mably commentedComment #9
mably commentedPathauto: Preserve consecutive spaces feature
These two commits introduce and refine a Pathauto setting that controls whether
consecutive whitespace characters are collapsed into a single separator or each
individually replaced, preserving the spacing in the resulting alias.
Commit 1 — Added a setting to keep number of spaces
Introduces the core feature (by contributor kksandr): a new setting that, when
enabled, replaces each whitespace character individually with the separator instead
of collapsing all consecutive whitespace into one. For example, with
-as separator,
"foo bar"becomes"foo--bar"instead of the default
"foo-bar".preserve_consecutive_spacescache key read from config; when enabled, uses
/\s/(single whitespace)instead of
/\s+/(one or more) for replacement.FALSE(existing behavior preserved).
Commit 2 — Rename and add test coverage
Renames
keep_number_of_spacestopreserve_consecutive_spacesfor consistency with
preserve_consecutive_separators, improves the formlabel and description, adds an update hook, and provides missing test coverage.
install defaults, AliasCleaner, settings form).
"Preserve consecutive spaces"; description now explains the concrete effect
(
"foo bar" → "foo--bar").pathauto_update_10001()to initialize the setting to
FALSEfor existing sites.preserve_consecutive_spacesto$defaultFormValuesandasserts the checkbox is unchecked by default.
testCleanStringWithPreserveConsecutiveSpaces()verifying:"foo bar"→"foo--bar"(two spaces → two separators)"foo bar"→"foo---bar"(three spaces → three separators)"foo bar"→"foo-bar"(single space unchanged)Comment #10
mably commented