Recommended Posts

Posted (edited)

An Images field allows you to:

  • Rename images by clicking the filename in the edit panel or in list view.
  • Replace images, keeping metadata and filename (when possible) by dropping a new image on the thumbnail in the edit panel. Introduced here.

But neither of these things is possible in File fields, which prompted this module. The way that files are renamed or replaced in this module is not as slick as in the Images field but it gets the job done. The most time-consuming part was dealing with the UI differences of the core admin themes. @tpr, gives me even more respect for the work that must go into AdminOnSteroids.

Most of the code to support the rename/replace features is already present in InputfieldFile - there is just no UI for it currently. So hopefully that means these features will be offered in the core soon and this module can become obsolete.

 

Files Rename Replace

Allows files to be renamed or replaced in Page Edit.

rename-replace

Usage

Install the Files Rename Replace module.

If you want to limit the module to certain roles only, select the roles in the module config. If no roles are selected then any role may rename/replace files.

In Page Edit, click "Rename/Replace" for a file...

Rename

Use the text input to edit the existing name (excluding file extension).

Replace

Use the "Replace with" select to choose a replacement file from the same field. On page save the file will be replaced with the file you selected. Metadata (description, tags) will be retained, and the filename also if the file extensions are the same.

Tip: newly uploaded files will appear in the "Replace with" select after the page has been saved.

 

https://github.com/Toutouwai/FilesRenameReplace
http://modules.processwire.com/modules/files-rename-replace/

Edited by Robin S
Added modules directory link.
  • Like 12
  • Thanks 2

Share this post


Link to post
Share on other sites

I have only recently started to work on something similar, only streamlined for frontend editing, so kudos for tackling that topic  :) I'm likely going to peek inside the code and steal a few pieces.

The only nitpick I have is that the behavior of the replacement option might not be clear to end users. The field should probably be a little more verbose and tell the user that description and/or tags are replaced by those of the selected file, or they might assume it's the other way round. Perhaps a "Replace with" option would be even more intuitive (use the selected file and keep the rest as is). It's how I'd write it as a user story - "I have a file entry on the page with a description and tags and just want to replace the old file with a new one in that entry". Just playing devil's advocate here, as I'm thinking of my 50+ intranet editors who only update their pages a few times every year.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, BitPoet said:

Perhaps a "Replace with" option would be even more intuitive (use the selected file and keep the rest as is).

I hear what you're saying, but the idea for this module is to bring the behaviour of the core Images field to the Files field (albeit in a less ambitious way). Ideally the Files field would have a dropzone similar to the edit panel thumbnail of the Images field, and a file uploaded via that dropzone would immediately replace the edited file. But tackling the Javascript that would be involved feels like too much work, hence the less elegant approach taken in this module. Pull requests from JS wizards would be welcome. :)

The way I'm imagining this module being used is you have a file with some metadata, and perhaps that file is linked to in a CKEditor field. You want to replace that file with another file (not yet uploaded) without having to manually copy the metadata or recreate the link in CKEditor. The new file is uploaded to the field and then immediately afterwards the target file is replaced. So it's like a poor man's version of the image replace feature, using the same underlying core code in InputfieldFile, in two steps instead of one.

I hadn't imagined the replacement file being one that has already existed in the field for a while and has metadata associated with it (my screencast demo wasn't that well thought out - I'll redo it). But I think it should be quite easy to support what you've suggested, via a checkbox next to the select for "Replace metadata also". Or some other wording you think would be clearer?

Share this post


Link to post
Share on other sites
1 hour ago, BitPoet said:

Perhaps a "Replace with" option would be even more intuitive (use the selected file and keep the rest as is).

I think I misunderstood you before. You're suggesting the dropdown would be "Replace with" and you would use the dropdown in the target file rather than the source file, and select a source file to be a replacement. I agree that is more intuitive, but the replace code in InputfieldFile doesn't work that way - each file can specify another file that it will replace, but not a file that will be it's own replacement. But I could go away from letting InputfieldFile handle the replacement and do it all within the module (I'm already having to handle the metadata and sort position).

Will have a think about it and may well change to that. So to any early adopters... be advised that the workflow may change. :)

Share this post


Link to post
Share on other sites

Module updated to v0.1.3. The workflow for replacing files is now reversed, because it's more intuitive that way. Readme and screencast updated.

  • Thanks 1

Share this post


Link to post
Share on other sites

Brilliant! I only now got a chance to reply, and you have already changed things around just the way I imagined. I'll take your module on a test drive in our intranet on Monday.

Share this post


Link to post
Share on other sites

That's a great solution!  Thanks Robin for providing this module.  I just installed it and noticed a minor issue:  See how the "R" in Rename and Replace gets cutoff?

replace.jpg.1f71aa3f419ef636c9abf97cfea7d8b4.jpg

Do you plan on adding it to the Modules directory?  It would make it easier to upgrade.

It would also be cool if you made a similar module to handle image fields the same way.  Maybe with an option to disable core's "click the filename to rename" feature and the drag and drop on thumbnail to swap the image?  That way file and image fields are consistently the same and the "Rename / Replace" feature would be controlled by a permission both for image and file fields.  I doubt many people know of those features any way?  Drag and drop an image on a thumbnail could be considered a destructive action that may not be the intended behavior of the user?

An easy way to disable the rename of the filename feature could be to remove the contenteditable attribute?

I'm in hurry right now, but I just wanted to share the few thoughts I had.

Thanks again

Share this post


Link to post
Share on other sites

@gmclelland, thanks for the feedback.

2 hours ago, gmclelland said:

It would also be cool if you made a similar module to handle image fields the same way.  Maybe with an option to disable core's "click the filename to rename" feature and the drag and drop on thumbnail to swap the image?

I don't want to reinvent the wheel for functionality that's already in the core. I'd actually prefer this module to be more like the Images field behaviour rather than the other way around. I would have done the file renaming the same way as the Images field but the filename is used as a link in the Files field. I will probably work on refining this module to be closer to the renaming/replacing behaviour of the Images field when I have time.

I also think Ryan does intend to bring renaming and replacing to the Files field, as the underlying code is in InputfieldFile and labelled with "currently only used by InputfieldImage".

2 hours ago, gmclelland said:

would be controlled by a permission both for image and file fields

We've talked previously about how to limit image renaming by a permission:

I don't think there's an easy way to prevent image replacement, but it doesn't really make sense to anyway because if a user has access to an Images inputfield then they can already upload and delete images which is no less destructive than replacing them.

2 hours ago, gmclelland said:

I just installed it and noticed a minor issue:  See how the "R" in Rename and Replace gets cutoff?

I can't see that here so hard for me to fix - it might be OS dependent. When you have a chance, could you have a play around with the CSS and see if you can find a solution? Hopefully without changing the position of the elements. Maybe take a look at line-height, overflow or z-index? Thanks.

2 hours ago, gmclelland said:

Do you plan on adding it to the Modules directory?

Yes, it is awaiting approval for the directory.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, Robin S said:

I don't want to reinvent the wheel for functionality that's already in the core. I'd actually prefer this module to be more like the Images field behaviour rather than the other way around. I would have done the file renaming the same way as the Images field but the filename is used as a link in the Files field. I will probably work on refining this module to be closer to the renaming/replacing behaviour of the Images field when I have time.

The problem with the core implementation is that isn't immediately discoverable that you can click the image's filename and rename it whereas your solution make's it obvious with a label "Rename / Replace."  Most content editors aren't very technical savvy.

Quote

We've talked previously about how to limit image renaming by a permission:

Ah..Forgot about that one.  Thanks

Quote

I can't see that here so hard for me to fix - it might be OS dependent. When you have a chance, could you have a play around with the CSS and see if you can find a solution? Hopefully without changing the position of the elements. Maybe take a look at line-height, overflow or z-index? Thanks.

I tried to take a look at tonight, but it looks a little more involved to get it just right across the different themes.  I think the cutoff text is due to the negative margins.  I'll investigate some more the next chance I get.  I'm running Chrome on a mac with the latest version of Processwire and AOS.

Share this post


Link to post
Share on other sites

@gmclelland, thanks for taking a look at the CSS. I've made some tweaks in v0.1.4 which will hopefully solve the cutoff text you were seeing. Let me know if not.

  • Like 2

Share this post


Link to post
Share on other sites

Strangely, I tried updating the module with the ProcessWireUpgrade module, but it gave me an error "Session: Invalid download URL specified."  It might have been because I originally downloaded the module from github.

The text looks good now, it's no longer cut off.  Thanks Robin!

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, gmclelland said:

Strangely, I tried updating the module with the ProcessWireUpgrade module, but it gave me an error "Session: Invalid download URL specified."

That was an error in the info at the modules directory, caused by mismatched browser autofill. Catches me out on a semi-regular basis. Would be nice if the modules directory used autocomplete attributes on the fields to give browsers some guidance for autofill.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.1.16
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
    • By MoritzLost
      UPDATE: I have published a stable version of this module!
      Discussion thread:
      Github: https://github.com/MoritzLost/TextformatterPageTitleLinks
      ---
      Hello there,
      I'm working on a tiny textformatter module that searches the text for titles of other pages on your site and creates hyperlinks to them. I'm not sure if something like this exists already, but I haven't found anything in the module directory, so I wrote my own solution 🙂
      It's not properly tested yet and is still missing some functionality I would like to implement, so at the moment it should be considered in BETA. Features include limiting the pages that will get searched by template, and adding a custom CSS class to the generated hyperlinks. As I'm writing this I noticed that it will probably include unpublished and hidden pages at the moment, so yeah ... it's still in development alright 😅
      You can download the module from Github:
      https://github.com/MoritzLost/TextformatterPageTitleLinks
      There's some more information in the readme as well.
      Anyway, let me know what you think! I'm happy about any feedback, possible improvements or ideas on how to improve the module. Cheers.
    • By blad
      Hi guys!
      I just uploaded a module to explore files based on elFinder. By default it will show the "Files" folder.
      Screenshots:

      Video:
       
      To do:
       More options To fix:
       The function of rotating or scaling an image fails  Image editors V 1.01 (view issue)
      Fixed the bug working with the Multi-Language support ( translation of folders ). Fixed the name of elfinder.en  Github:
      https://github.com/LuisSantiago/ProcessElFinder/
      I hope you like it.
    • By BitPoet
      I'm really in love with FormBuilder, but the one thing missing to match all my end users' expectations were repeatable field groups. Think repeaters, in ProcessWire terms. Our primary application of PW is our corporate intranet, so "lines" of fields are quite common in the forms I build. We have all kinds of request forms where the information for a varying number of colleagues needs to be entered (from meal order to flight booking request) and where it is simply impractical to send a form for each, and I don't want to clutter my forms with multiple instances of fields that may only get used ten percent of the time.
      That's why I started to build FormBuilderMultiplier (link to GitHub).
      What it does:
      Adds an option to make a regular Fieldgroup repeatable Lets you limit the number of instances of a Fieldgroup on the form Adds an "Add row" button the form that adds another instance of the Fieldgroup's fields Adds a counter suffix at the end of every affected field's label Stores the entered values just like regular fields Makes the entered values available in preview and email notifications Supports most text based fields, textareas and selects (really, I haven't had enough time to test all the available choices yet) What it doesn't do (yet):
      Support saving to ProcessWire pages (i.e. real Repeaters) I haven't tested all the validation stuff, Date/Time inputs etc. yet, but since I'm utterly swamped with other stuff at work, I didn't want to wait until I have it polished. Any feedback is welcome. There might also be some issues with different output frameworks that I haven't encountered yet. The forms I work with mostly use UIKit.
      Status:
      Still alpha, so test well before using it in the field.
      Known issues:
      When rows are added, the form's iframe needs to be resized, which isn't completely clean yet.
      How it works:
      The Fieldgroup settings are added through regular hooks, as is the logic that adds the necessary field copies for processing the form and displaying previews.
      "Multiplied" field instances are suffixed with _NUM, where NUM is an incremental integer starting from 1. So if you have add two fields named "surname" and "givenname" to a fieldgroup and check the "multiply" checkbox, the form will initially have "surname_1" and "givenname_1" field (I'm still considering changing that to make the risk to shoot oneself into the foot by having a regular "surname_1" field somewhere else in the form less likely).
      When a "row" is added, the first row is cloned through JS and the counter in the fields' IDs, names and "for" attributes as well as the counter in the label are incremented before appending the copies to the Fieldset container in the form.
      To keep backend and frontend in sync, a hidden field named [name of the fieldset]__multiplier_rows is added to the form. Both the backend and the frontend script use this to store and retrieve the number of "rows".
      ToDo:
      Naturally, add the option to store the data in real repeaters when saving to pages. Do a lot of testing (and likely fixing). Make a few things (like the "Add row" button label etc.) configurable in field(set) context. Add a smooth API to retrieve the multiplied values as WireArrays. The mandatory moving screenshot: