Skip to content
Snippets Groups Projects
Commit 375303cc authored by jdhildeb's avatar jdhildeb Committed by Nikolay Grachev
Browse files

Issue #3374494 by jdhildeb: Improve usability by opening rename form in new tab

parent b5edb5ce
No related branches found
No related tags found
No related merge requests found
......@@ -171,9 +171,17 @@ function file_rename_file_prerename(FileInterface $file) {
*/
function _file_rename_widget_custom_process(array $element, FormStateInterface $form_state, array $form) {
$parents_prefix = implode('_', $element['#parents']);
$request_destination = \Drupal::requestStack()
->getCurrentRequest()
->getPathInfo();
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'entity.node.edit_form') {
// the rename form will open in a new tab. After the user saves, take them to node view page.
// (We don't want them to be editing the same node in two different tabs.)
$node = \Drupal::routeMatch()->getParameter('node');
$request_destination = Url::fromRoute('entity.node.canonical', ['node' => $node->id()])->toString();
} else {
$request_destination = \Drupal::requestStack()
->getCurrentRequest()
->getPathInfo();
}
$file_id = $element['#default_value']['target_id'];
$element['rename_link'] = [
'#name' => $parents_prefix . '_rename_link',
......@@ -190,6 +198,7 @@ function _file_rename_widget_custom_process(array $element, FormStateInterface $
'#suffix' => '</small>',
'#attributes' => [
'class' => ['admin-link'],
'target' => '_blank',
],
'#attached' => ['library' => ['file_rename/backend-styles']],
];
......
......@@ -62,6 +62,10 @@ class FileRenameForm extends ContentEntityForm {
'#field_suffix' => "<strong>.{$pathinfo['extension']}</strong>",
];
$form['info'] = [
'#markup' => '<p>This page opened in a new tab.<br>After you save this form, <b>return to your original tab</b> to make sure you save any changes you made there.</p>',
];
$form['usages'] = [
'#markup' => '<p><a href="/admin/content/files/usage/' . $this->entity->id() . '" target="_blank">' . $this->t('See file usages') . '</a></p>',
];
......@@ -132,6 +136,7 @@ class FileRenameForm extends ContentEntityForm {
$pathinfo = pathinfo($this->entity->getFileUri());
$filename_new = $form_state->getValue('new_filename') . '.' . $pathinfo['extension'];
$reminder = $this->t("Don't forget to return to your original tab and save any changes you made there.");
if ($filename_new != $this->entity->getFilename()) {
$filepath_new = $this->getRenamedFilePath($form_state);
// Invoke pre-rename hooks.
......@@ -152,8 +157,10 @@ class FileRenameForm extends ContentEntityForm {
// Invoke hooks if there are some.
$this->moduleHandler->invokeAll('file_rename', [$this->entity]);
$this->messenger()->addWarning($reminder);
return $status;
}
$this->messenger()->addWarning($reminder);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment