Problem/Motivation:
When users clone content using the Entity Clone module, the resulting cloned content does not retain the URL alias of the original item. Instead, the system-generated node path (e.g., node/123) is used when visiting the cloned content. This behavior diverges from what might be expected, where a user assumes that all properties, including the URL alias, would be duplicated.
Steps to Reproduce:
- Install and set up a Drupal site.
- Enable the Entity Clone module.
- Create a new content type.
- Add path alias for the content type.
- Create content using the newly created content type and specify a URL alias for the content.
- Visit the content and verify the URL alias is used in the page URL.
- Use the Entity Clone module to clone the content.
- Visit the cloned content and observe that the URL remains in the format of node/nid (e.g., node/xxx), despite the alias being visible upon re-editing the content.
Proposed Resolution:
Ideally, cloned content should preserve the URL alias from the source content. A modification is needed in the Entity Clone module to copy the URL alias when the cloning action is performed, while ensuring the uniqueness of the aliases. This implies that the cloned content may have a suffix or a differentiating factor added to the original alias to maintain a unique URL for each piece of content. The solution should make it possible to provide the URL alias for cloned content automatically during the cloning process.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff_12-14.txt | 29.31 KB | kbrodej |
| #14 | 3103935-14.patch | 25.18 KB | kbrodej |
| #12 | interdiff_8-12.txt | 16.19 KB | ngkoutsaik |
| #12 | move_to_submodule-3103935-12.patch | 8.62 KB | ngkoutsaik |
Issue fork entity_clone-3103935
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 #2
Syntapse commentedComment #3
Syntapse commentedComment #4
nginex commentedHello @Syntapse,
As you know the alias should be unique and it can't be cloned to the same value. Would you expect some kind of prefix for the alias like -clone
For example:
- original alias is /my-custom-content
- cloned alias would be /my-custom-content-clone
is it your expectation or you have better idea?
Comment #5
kbrodej commentedHi. Created a patch which adds this functionality mentioned in #4
Comment #6
kbrodej commentedChanged the issue to Needs review.
Comment #7
deaom commentedHi @kbrodej and thanks for the patch. It does apply and adds the *_cloned to the alias. Maybe just instead of underline (_) you should add bind (-). So just for that reason marking it as needs work.
Comment #8
strozx commentedHi, I changed the _ to - because as @DeaOm said it's better to have - than _.
Regards
Comment #9
deaom commentedHi @strozx, the patch applies and works, writing the alias with the dash instead of underline. Good job, marking it as RTBC.
Comment #10
vpeltot commentedRather than doing an if ..., assuming the module pathauto is not necessary enabled, it will be better to create a new submodule
entity_clone_pathautoto provide this feature by subscribing to theEntityCloneEvents::POST_CLONEevent.In addition, Nodes are not the only entity types that pathauto can manage.
Comment #11
vpeltot commentedComment #12
ngkoutsaik commentedHere is an updated patch. The fix is now an additional module.
Additionally it is not limited only to node types.
Comment #13
ngkoutsaik commentedComment #14
kbrodej commentedHi. Reviewed the patch. it makes more sense to be in a submodule.
I made some changes.
- Renamed the submodule as it does not use pathauto to create cloned alias
- Decluttered the code from event subsriber to services.
- Added a condition for cloning of alias
- Wrote tests for cloning an alias.
What could be added is an entity settings form to enable or disable cloning of the aliases on child classes of respective entity types. eg. bundles on node etc.
Comment #16
rajeshreeputrapatch need to be re-roll with latest code.
Comment #17
soutams commented@kbrodej The patch is not compatible with the latest version.
Comment #18
rajeshreeputraComment #20
rajeshreeputraComment #21
rajeshreeputraRequesting review.
Comment #22
rajeshreeputraComment #24
andreasderijckeWhile trying this solution, we're still missing aliases in translations.
This is because the check
if ($this->pathAliasManager->getPathByAlias($cloned_path_alias) === $cloned_path_alias) {(https://git.drupalcode.org/issue/entity_clone-3103935/-/blob/3103935-dru...) is false.
It is is unclear to me what the reasoning is behind this piece of code.
Comment #25
andreasderijcke