Jump to content

Recommended Posts

Posted

AFAIK there isn't any way to do this currently.  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.

  • Like 1
Posted
On 07/11/2017 at 9:45 PM, Zeka said:

rename uploaded files through admin UI as it possible with images

How do you rename images through the admin UI? I wasn't aware that was possible.

Posted
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.

Posted

Thanks Robin,

That sounds like it would work client side, 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.

Posted
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
Posted

@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
Posted
1 minute ago, kongondo said:

Shouldn't this not be negated?

How do you mean? The test is if the user doesn't have the permission then the contenteditable attribute does get removed.

Posted
8 hours ago, Robin S said:

The test is if the user doesn't have the permission then the contenteditable attribute does get removed.

My bad, sorry. Understood it the other way round.

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
  • Recently Browsing   0 members

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