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 BitPoet
      MediaLibrary
      Update: MediaLibrary can now be found in the official module list.
      Out of necessity, I've started to implement a simple media library module.
      The basic mechanism is that it adds a MediaLibrary template with file and image fields. Pages of this type can be added anywhere in the page tree.
      The link and image pickers in CKEditor are extended to allow quick selection of library pages from dropdowns. In the link picker this happens in the MediaLibrary tab, where you can also see a preview of the selected image. In the image picker, simply select a library from the dropdown at the top, everything else is handled by standard functionality.
      I've put the code onto github. This module is compatible with ProcessWire 3.
      Steps to usage:
      Download the module's zip from github (switch to the pw3 branche beforehand if you want to test on PW 3.x) and unpack it into site/modules Click "Modules" -> "Refresh" in the admin Click "Install" for MediaLibrary For testing, create a page with the MediaLibrary template under home (give it an expressive title like 'Global Media') and add some images and files Edit a differnt page with a CKEditor field and add a link and an image to see the MediaLibrary features in action (see the screencap for details) Optionally, go into the module settings for MediaLibrary Note: this module is far from being as elaborate as Kongondo's Media Manager (and doesn't plan to be). If you need a feature-rich solution for integrated media management, give it a look.
      Feel free to change the settings for MediaFiles and MediaImages fields, just keep the type as multiple.
      There are some not-so-pretty hacks for creating and inserting the correct markup, which could probably be changed to use standard input fields, though I'm a bit at a loss right now how to get it to work. I've also still got to take a look at error handling before I can call it fit for production. All feedback and pointers are appreciated (that's also why I post this in the development section).

      Edit 09.03.2016 / version 0.0.4: there's now also a "Media" admin page with a shortcut to quickly add a new library.

      Edit 01.05.2016:
      Version 0.0.8:
      - The module now supports nested media libraries (all descendants of eligible media libraries are also selectable in link/image picker).
      - There's a MediaLibrary::getPageMediaLibraries method you can hook after to modify the array of available libraries.
      - You can switch between (default) select dropdowns or radio boxes in the module configuration of MediaLIbrary to choose libraries.
      Edit 10.10.2018:
      Version 0.1.3:
      - Dropped compatibility for ProcessWire legacy versions by adding namespaces
      - Allow deletion of libraries from the Media overview admin page
      - Added an option to hide media libraries from the page tree (optionally also for superusers)
    • By rgaikema
      Hi all,
      Hopefully there's somebody who can help me with an issue while unzipping files.
      My goal is to show banners in a portfolio.
      In ProcessWire I have created a field, type 'Files', where I can upload the .zip files, one at a time.
      I've selected the option Decompress ZIP files, but any subfolder in the .zip somehow disappears.
      For example the 'assets' folder is gone after I uploaded the .zip file (see the attachment for the file structure).
      I'm curious, is there a way to preserve the file structure inside a .zip file after unzipping it?
       
      Kind regards,
      Remco

    • By Robin S
      This module corrects a few things that I find awkward about the "Add New Template" workflow in the PW admin. I opened a wishlist topic a while back because it would good to resolve some of these things in the core, but this module is a stopgap for now.
      Originally I was going to share these as a few standalone hooks, but decided to bundle them together in a configurable module instead.
      Add Template Enhancements
      A module for ProcessWire CMS/CMF. Adds some efficiency enhancements when adding or cloning templates via admin.

      Features
      Derive label from name when new template added: if you like to give each of your templates a label then this feature can save some time. The label can be added automatically when templates are added in admin, in admin/API, or not at all. There are options for underscore/hyphen replacement and capitalisation of the label. Edit template after add: when adding only a single template, the template is automatically opened for editing after it is added. Copy field contexts when cloning: this copies the field contexts (a.k.a. overrides such as column width, label and description) from the source template to the new template when using the "Duplicate/clone this template?" feature on the Advanced tab. Copy field contexts when duplicating fields: this copies the field contexts if you select the "Duplicate fields used by another template" option when adding a new template. Usage
      Install the Add Template Enhancements module.
      Configure the module settings according to what suits you.
       
      https://github.com/Toutouwai/AddTemplateEnhancements
      https://modules.processwire.com/modules/add-template-enhancements/
    • By Guy Incognito
      Hi all. We've created a private log-in area for a client on their site that is restricted on a roles basis. Is there a simple solution available to let them upload files to a file field and then choose individual users that can access individual files?
      Does that make sense?!... it's hard to search for answers to this as all results pertain to server file permissions.
       
    • By Mike Rockett
      As I mentioned in this issue, I've create a new textformatter for ParsedownExtraPlugin, which adds some oomph to your markdown.
      Repo: Parsedown Extra Plugin
      Unlike the built-in textformatter for Parsedown and Parsedown Extra, this should be used when you want to use Extra with additional configuration/customisation.
      Some examples:
      ### Test {.heading} - A [external link](https://google.com/){.google} with `google` as a class that opens in a new tab if the config property is set. - [Another link](/page){target=_blank} that opens in a new tab even though it isn't external. ```html .html <p>Test</p> ``` There's some config options available to you, such as setting attributes on all/external images and links, setting table and table-cell alignment classes, adjusting footnote classes and IDs, adding <code> attributes to their parent <pre> elements, and changing the <code> class if your syntax highlighter does not use language-*.
      I was thinking about adding the ability to make links open in a new tab by appending a plus to the link syntax, but only external links should be opening in a new tab anyway. Further, this would add extra, unnecessary processing time.
      Please let me know if you bump into any problems. ☺️