Refactor alias and title increment logic in StringHelper #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for Issue #45011
Summary of Changes
Modified the increment function in the StringHelper file with the same logic @chmst suggested. First, the function checks the format of the string by determining the style. If the default style is used, it checks if the string contains a number inside parentheses. If a number is present, it increments the number inside the parentheses. If no number is found, it appends (2) to the title. If the dash style is used, it checks if the string ends with a number preceded by a hyphen. If a number is present, it increments it. If no number is found, it appends -2 to the alias. I would appreciate any help or suggestions to ensure this solution works as expected across various use cases.
Testing Instructions
When merged with joomla-cms,
Example Test: Create an article that has
Title: August 2024
Alias: august-2024
Save as copy
Title: August 2024 (2)
Expected Alias: august-2024-2
This method supports two formats for string incrementing:
Title Format (Default Style): For titles, the increment will be handled inside parentheses.
"dog"
becomes"dog (2)"
, and"dog (2)"
becomes"dog (3)"
.(2)
by default.Alias Format (Dash Style): For aliases, the increment will be handled with a hyphen (
-
)."dog-2"
becomes"dog-3"
.-2
by default.alias_issue.2.mp4
Documentation Changes Required