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 Soma
      LogMaintenance
      A simple ProcessWire module to give some maintenance control over log files. I found myself often having lots of log files for different things that can grow more or less quickly to a size where they can be difficult to maintain. The built in Logger of PW does a good job of giving you the possibility to delete or prune logs. But it has to be done manually and sometimes a log grows into millions of lines, which makes it often impossible to even prune it as it's too large.
      LogMaintenance uses LazyCron to run the maintenance task and there's several settings you can setup on a global or per log basis.
      Archive: will create zip files for each log file in logs/archive/ folder and add the log each time the maintenance is run to a subfolder containing the datetime.
      Lines: keeps logs to a certain number of lines 
      Days: keeps the log to a certain number of days
      Bytes: keeps the log to a certain amount of bytes
      Each setting is checked from top down, the first setting to contain something is used. So if you check the "Archive" option, all other settings are ignored and logs are archived everytime the LazyCron is executed. If you want to keep your logs to a certain amount of bytes just leave all other settings to 0 or blank.
      Per Log Settings
      There's a textarea that you can use to setup a config for a specific log file one per line. All the logs you define here ignore the global settings above. The syntax for the settings is:
      logname:[archive]:[lines]:[days]:[bytes] 
      errors:1:0:0:0 // would archive the errors log messages:0:10000:0:0 // will prune the errors log to 10000 lines  
      The module can be found on github for you to check out. It's still fresh and I'm currently testing.
      https://github.com/somatonic/LogMaintenance
    • By teppo
      Fieldtype Page IDs is a third party Fieldtype that, simply put, stores Page references as integers (Page IDs).
      This fieldtype was built as a quick and dirty workaround for Page Reference fields' inability handle self-references due to circular reference issues. A project I've been working on for a while now includes a combination of RepeaterMatrix content blocks and tagging/categorization system that would've resulted in a lot of duplicate pages (and plenty of unnecessary manual work for content editors) had I used built-in Page Reference fields, and thus a new Fieldtype felt like the most sensible approach.
      Fieldtype Page IDs was designed to be loosely compatible with Page References in order to make conversions between the two feasible, but it is quite limited feature wise:
      largely due to the fact that stored values are actually just integers with no connection to Pages whatsoever some advanced selectors and related features are not supported, and page values can't be directly accessed configuration settings are limited to the bare essentials (selector string and Inputfield class) only a handful of Inputfields (AsmSelect, Checkboxes, Text) are (currently) supported Anyway, in case you need to store Page IDs (and Page IDs only) and are happy with the limitations mentioned above, feel free to give this Fieldtype a try. It has been working fine for me in one particular project, but hasn't been tested that much, so please tread carefully – and let me know if you run into any issues.
      GitHub repository: https://github.com/teppokoivula/FieldtypePageIDs
      Modules directory: https://modules.processwire.com/modules/fieldtype-page-ids/
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      I've updated the module to 0.0.4. I removed the instructions from this forum, so I don't have to maintain it on multiple places. Just checkout the readme on github 🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github. 
    • By bernhard
      WHY?
      This module was built to fill the gap between simple $pages->find() operations and complex SQL queries.
      The problem with $pages->find() is that it loads all pages into memory and that can be a problem when querying multiple thousands of pages. Even $pages->findMany() loads all pages into memory and therefore is a lot slower than regular SQL.
      The problem with SQL on the other hand is, that the queries are quite complex to build. All fields are separate tables, some repeatable fields use multiple rows for their content that belong to only one single page, you always need to check for the page status (which is not necessary on regular find() operations and therefore nobody is used to that).
      In short: It is far too much work to efficiently and easily get an array of data based on PW pages and fields and I need that a lot for my RockGrid module to build all kinds of tabular data.

      Basic Usage

       
      Docs & Download
      https://modules.processwire.com/modules/rock-finder/
      https://gitlab.com/baumrock/RockFinder/tree/master
       
      Changelog
      180528, v1.0.4 add custom select statement option 180516 change sql query method, bump version to 1.0.0 180515 multilang bugfix 180513 beta release <180513 preview/discussion took place here: https://processwire.com/talk/topic/18983-rocksqlfinder-highly-efficient-and-flexible-sql-finder-module/
    • By blynx
      Hej,
      A module which helps including Photoswipe and brings some modules for rendering gallery markup. Feedback highly appreciated
      (Also pull requests are appreciated 😉 - have a new Job now and don't work a lot with ProcessWire anymore, yet, feel free to contact me here or on GitHub, Im'm still "online"!)

      Modules directory: http://modules.processwire.com/modules/markup-processwire-photoswipe
      .zip download: https://github.com/blynx/MarkupProcesswirePhotoswipe/archive/master.zip
      You can add a photoswipe enabled thumbnail gallery / lightbox to your site like this. Just pass an image field to the renderGallery method:
      <?php $pwpswp = $modules->get('Pwpswp'); echo $pwpswp->renderGallery($page->nicePictures); Options are provided like so:
      <?php $galleryOptions = [ 'imageResizerOptions' => [ 'size' => '500x500' 'quality' => 70, 'upscaling' => false, 'cropping' => false ], 'loresResizerOptions' => [ 'size' => '500x500' 'quality' => 20, 'upscaling' => false, 'cropping' => false ], 'pswpOptions' => (object) [ 'shareEl' => false, 'indexIndicatorSep' => ' von ', 'closeOnScroll' => false ] ]; echo $pswp->renderGallery($page->images, $galleryOptions); More info about all that is in the readme: https://github.com/blynx/MarkupProcesswirePhotoswipe
      What do you think? Any ideas, bugs, critique, requests?
      cheers
      Steffen