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.

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

Syntapse created an issue. See original summary.

Syntapse’s picture

Title: aliases don't save or apply to cloned content. » drupal 8.6: aliases don't save on cloned content.
Issue summary: View changes
Syntapse’s picture

Version: 8.x-1.x-dev » 8.x-1.0-beta1
nginex’s picture

Hello @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?

kbrodej’s picture

StatusFileSize
new8.42 KB

Hi. Created a patch which adds this functionality mentioned in #4

kbrodej’s picture

Status: Active » Needs review

Changed the issue to Needs review.

deaom’s picture

Status: Needs review » Needs work

Hi @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.

strozx’s picture

Status: Needs work » Needs review
StatusFileSize
new8.42 KB
new686 bytes

Hi, I changed the _ to - because as @DeaOm said it's better to have - than _.

Regards

deaom’s picture

Status: Needs review » Reviewed & tested by the community

Hi @strozx, the patch applies and works, writing the alias with the dash instead of underline. Good job, marking it as RTBC.

vpeltot’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Form/EntityCloneForm.php
@@ -162,6 +212,33 @@ class EntityCloneForm extends FormBase {
+    if ($pathauto_enabled && $this->entity instanceof NodeInterface) {

Rather than doing an if ..., assuming the module pathauto is not necessary enabled, it will be better to create a new submodule entity_clone_pathauto to provide this feature by subscribing to the EntityCloneEvents::POST_CLONE event.
In addition, Nodes are not the only entity types that pathauto can manage.

vpeltot’s picture

Issue tags: +Needs tests
ngkoutsaik’s picture

StatusFileSize
new8.62 KB
new16.19 KB

Here is an updated patch. The fix is now an additional module.

Additionally it is not limited only to node types.

ngkoutsaik’s picture

Status: Needs work » Needs review
kbrodej’s picture

StatusFileSize
new25.18 KB
new29.31 KB

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

Status: Needs review » Needs work

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

rajeshreeputra’s picture

patch need to be re-roll with latest code.

soutams’s picture

@kbrodej The patch is not compatible with the latest version.

rajeshreeputra’s picture

Version: 8.x-1.0-beta1 » 2.x-dev

rajeshreeputra’s picture

Title: drupal 8.6: aliases don't save on cloned content. » Provide aliases to cloned content.
Category: Bug report » Feature request
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests
rajeshreeputra’s picture

Requesting review.

rajeshreeputra’s picture

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

andreasderijcke’s picture

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

andreasderijcke’s picture

Status: Needs review » Needs work