Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
file_rename
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
file_rename
Commits
375303cc
Commit
375303cc
authored
1 year ago
by
jdhildeb
Committed by
Nikolay Grachev
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3374494
by jdhildeb: Improve usability by opening rename form in new tab
parent
b5edb5ce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
file_rename.module
+12
-3
12 additions, 3 deletions
file_rename.module
src/Form/FileRenameForm.php
+7
-0
7 additions, 0 deletions
src/Form/FileRenameForm.php
with
19 additions
and
3 deletions
file_rename.module
+
12
−
3
View file @
375303cc
...
...
@@ -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'
]],
];
...
...
This diff is collapsed.
Click to expand it.
src/Form/FileRenameForm.php
+
7
−
0
View file @
375303cc
...
...
@@ -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
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment