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
3a987bb4
Commit
3a987bb4
authored
1 year ago
by
Nikolay Grachev
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3394697
by granik, greenSkin: Add action link to rename file
parent
375303cc
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.info.yml
+1
-1
1 addition, 1 deletion
file_rename.info.yml
file_rename.module
+37
-0
37 additions, 0 deletions
file_rename.module
with
38 additions
and
1 deletion
file_rename.info.yml
+
1
−
1
View file @
3a987bb4
name
:
File Rename
description
:
Adds a possibility to rename managed files.
core_version_requirement
:
^8.
7.7
|| ^9 || ^10
core_version_requirement
:
^8.
9
|| ^9 || ^10
type
:
module
package
:
File
dependencies
:
...
...
This diff is collapsed.
Click to expand it.
file_rename.module
+
37
−
0
View file @
3a987bb4
...
...
@@ -5,9 +5,12 @@
* Contains file_rename.module.
*/
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\Core\Field\WidgetInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Url
;
use
Drupal\file\FileInterface
;
use
Drupal\file\Plugin\Field\FieldWidget\FileWidget
;
...
...
@@ -224,3 +227,37 @@ function _file_rename_widget_link_is_enabled_globally() {
function
_file_rename_link_is_enabled_for_widget
(
WidgetInterface
$widget
)
{
return
!
empty
(
$widget
->
getThirdPartySetting
(
'file_rename'
,
'show_rename_link'
));
}
/**
* Adds rename action link for file entities.
*
* Implements hook_entity_operation().
*/
function
file_rename_entity_operation
(
EntityInterface
$entity
)
{
$operations
=
[];
if
(
$entity
instanceof
FileInterface
&&
$entity
->
access
(
'rename'
)
&&
$entity
->
isPermanent
())
{
$operations
[
'rename'
]
=
[
'title'
=>
t
(
'Rename'
),
'url'
=>
Url
::
fromRoute
(
'entity.file.rename_form'
,
[
'file'
=>
$entity
->
id
(),
]),
'weight'
=>
100
,
];
}
return
$operations
;
}
/**
* Checks user permission for 'rename' operation.
*
* Implements hook_entity_access().
*/
function
file_rename_entity_access
(
EntityInterface
$entity
,
$operation
,
AccountInterface
$account
)
{
if
(
$entity
instanceof
FileInterface
&&
$operation
===
'rename'
)
{
return
$account
->
hasPermission
(
'rename files'
)
?
AccessResult
::
allowed
()
->
cachePerPermissions
()
:
AccessResult
::
forbidden
()
->
cachePerPermissions
();
}
return
AccessResult
::
neutral
();
}
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