Zeka Posted November 7, 2017 Share Posted November 7, 2017 Is there some way to rename uploaded files through admin UI as it possible with images? 1 Link to comment Share on other sites More sharing options...
gmclelland Posted November 8, 2017 Share Posted November 8, 2017 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. 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 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. Link to comment Share on other sites More sharing options...
gmclelland Posted November 8, 2017 Share Posted November 8, 2017 3 Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 @gmclelland, I just figured it out by clicking around as you replied. Cool, I had no idea that was possible! Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 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 More sharing options...
gmclelland Posted November 8, 2017 Share Posted November 8, 2017 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. Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 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. 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 @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); } }); 3 Link to comment Share on other sites More sharing options...
kongondo Posted November 8, 2017 Share Posted November 8, 2017 20 minutes ago, Robin S said: if(!$this->user->hasPermission('rename-images')) Shouldn't this not be negated? Link to comment Share on other sites More sharing options...
Robin S Posted November 8, 2017 Share Posted November 8, 2017 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. Link to comment Share on other sites More sharing options...
kongondo Posted November 9, 2017 Share Posted November 9, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now