Jump to content

Rename uploaded files


Zeka
 Share

Recommended Posts

1 hour ago, gmclelland said:

I also wish there was a dedicated permission for renaming files.  There are some cases were I don't want certain users to rename any uploaded files.

An idea on how you could achieve this:

Add a body class in admin according to the user's role:

This has also been added to AdminOnSteroids if you are using that.

Then add a custom javascript to ProcessPageEdit that selects .InputfieldImageEdit__name inside a particular body class and removes the "contenteditable" attribute from the inner <span>. You'd put this into a function and have it fire on domready and ajaxcomplete events.

Link to comment
Share on other sites

9 minutes ago, gmclelland said:

but I would think that kind of stuff should ideally be handled with server side code to remove the contenteditable attribute based on if the user has permission

Sure, but I suspect that if you look at the code that creates the inputfield markup there will be nothing hookable that lets you change that attribute in isolation. And it might be a long time before such a thing gets implemented in the core given the number of existing feature requests. Often you just have to do what you can to solve this kind of thing yourself.

Edit: if there's nothing else in the inputfield with the contenteditable attribute apart from the name fields you might be able to do a string replace on the markup returned from InputfieldImage::render to strip out that attribute. Pretty hacky but no more so than the JS approach I guess.

  • Like 1
Link to comment
Share on other sites

@gmclelland, turns out it is a piece of cake with str_replace.

Create a custom permission "rename-images" and give that to roles that you want to allow to rename images.

Then add the following to /site/ready.php

$wire->addHookAfter('InputfieldImage::renderItem', function(HookEvent $event) {
    if(!$this->user->hasPermission('rename-images')) {
        $event->return = str_replace(" contenteditable='true'", "", $event->return);
    }
});

 

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...