Problem:
When a node is replicated, the redirect goes to the newly created node. The user has to navigate back to the content listing page (admin/content) and edit it.

Solution:

  • Redirect the user back to the edit page for the replicated node

Comments

mustafa_abdalle created an issue. See original summary.

mustafa_ab’s picture

a simple patch for the issue

benjifisher’s picture

Status: Active » Needs work

@mustafa_abdalle:

Thanks for opening this issue and supplying a patch.

When you provide a patch, remember to set the issue status to Needs Review (NR). That alerts the module's maintainers and other users (like me) that there is a patch available.

I reviewed and tested the patch. It works as expected, and in my opinion any project that wants to load the Edit form after replicating an entity can safely use this patch.

I am setting the status to Needs Work (NW) because I think that the redirect should be made an option instead of changing it unconditionally.

I also have one nit to pick: the code comment "return to Edit page" is inaccurate. The redirection goes to the Edit page of the newly created entity. We have never been there, so "return" is not right.

Work-around

Instead of applying this patch, you can get the same effect by adding something like this to a custom module:

/**
 * Implements hook_form_FORM_ID_alter() for node_TYPE_replicate_form.
 */
function mymodule_form_node_TYPE_replicate_form_alter(array &$form, FormStateInterface $form_state) {
  $form['actions']['submit']['#submit'][] = '_mymodule_replicate_submit';
}

/**
 * Redirect to the edit form after replicating a  node.
 *
 * @param array $form
 *   The form array.
 * @param Drupal\Core\Form\FormStateInterface $form_state
 *   The current state of the form.
 */
function _mymodule_replicate_submit(array &$form, FormStateInterface $form_state) {
  $replicated_entity = $form_state->get('replicated_entity');
  $form_state->setRedirectUrl($replicated_entity->toUrl('edit-form'));
}

Replace TYPE with the content type (or entity bundle) you are replicating.

benjifisher’s picture

Oops, I did not actually test the patch in #2 when I wrote that comment. It needs an update since the code no longer contains drupal_set_message().

I am attaching an updated patch. I also changed the code comment.

The issue status is still NW because we should add a configuration option for this change.

chop’s picture

Would love to see this functionality brought into the Replicate UI module.

This redirect behaviour is something we've wanted for a long time. We used to be able to install the Replicate Bonus module, to provide a redirect back to the edit form.

https://www.drupal.org/project/replicate_bonus

Replicate Bonus is now unmaintained and has no Drupal 9 compatible release. There is a merge request to update it to Drupal 9 but nobody is able to merge it.

ruslan piskarov’s picture

Also, https://www.drupal.org/project/replicate_actions implements EventSubscriberInterface and makes redirects to node/edit page after replicating a node.

simohell’s picture

I did a survey on cloning content recently (you can find it from the DrupalCon Lille recordings soonish, or already now if you attended) and my question on redirect is: which language version? If this goes to module this is fairly important question for multilingual.

Also this goes hand-in-hand with alerting user if the entity (or with multilingual entities) was already published as the form view somewhat suggest that it is still in creation phase.

anybody’s picture

I'd very much vote to merge all the helpful base functionality into replicate_ui directly, for example as setting.
Until that, we should at least list the module on the module page: #3554704: List replicate_actions on the module page

anybody’s picture

Version: 8.x-1.0-rc1 » 8.x-1.x-dev
anybody’s picture