Jump to content

File Mover


Robin S
 Share

Recommended Posts

File Mover

Allows the selection of files or images for moving or copying to a different field. The destination field can be on the same page as the source field or on a different page.

Screencast


For convenience in the screencast this demonstration shows moving and copying images and files between fields on the same page, but you can also move/copy between pages by following the same process.

File Mover screencast

Usage


  1. In any Images or Files field, hover on the field label to show the File Mover icon. Clicking on the icon will reveal the File Mover buttons.
  2. If no items are yet selected you'll see a button labelled "Select items to later move or copy". Click the button to enter selection mode.
  3. While in selection mode, click one or more images/files to select them. When you have finished selecting items click the "Done" button. Note: you can only select from one Images and one Files field at a time before completing the move/copy step.
  4. In the Images or Files field that you want to move/copy the items to, hover the label to show the File Mover icon and click it to reveal the File Mover buttons.
  5. When you click the Move or Copy button the page will automatically be saved and the selected items will be moved or copied accordingly. There is also a button to clear the current selection if needed. If you hover on any of the buttons a tooltip shows the filenames of the currently selected items, in case you need a reminder.

Configuration


There is a field in the module config that defines which roles are allowed to use the File Mover module. If the field is left empty then all roles are allowed.

 

https://github.com/Toutouwai/FileMover
https://processwire.com/modules/file-mover/

  • Like 13
  • Thanks 9
Link to comment
Share on other sites

  • 2 weeks later...
  • 11 months later...

The module is great. Would it be possible to have like a batch that moves all images from one field to another field. Because i have hundreds of images in different field.

Link to comment
Share on other sites

17 hours ago, Flashmaster82 said:

Would it be possible to have like a batch that moves all images from one field to another field.

No, because this module is a helper for the admin interface. Doing bulk operations on a set of pages is what the PW API is for. The key method you would use for this is Pageimages::add().

The basic idea assuming two different pages are involved:

// Get the first page in whatever way you like
$p_1 = $pages(1234);
// Turn off output formatting
$p_1->of(false);
// Get the image from the image_1 field
// The first() method is used because the value of an image field
// is always a Pageimages object when output formatting is off
$image = $p_1->image_1->first();

// Get the second page in whatever way you like
$p_2 = $pages(1235);
// Turn off output formatting because you are about to change a field value
$p_2->of(false);
// Add the image to the image_2 field on the second page
// This is an example of Pageimages::add()
$p_2->image_2->add($image);
// Save the change to the second page
$p_2->save('image_2');

// Now perhaps you want to remove the image from the first page?
$p_1->image_1->remove($image);
$p_1->save('image_1');

If you are copying between two fields on the same page you'll have to work around this issue: https://github.com/processwire/processwire-issues/issues/1863

In FileMover I deal with this by calling Pagefile::install()https://github.com/Toutouwai/FileMover/blob/0020e365557730e59bad87286548e69f562be0d8/FileMover.module.php#L165-L166

The filename will then be automatically incremented. The incremented filename is something you'll want to consider if anything is linking directly to the image as the link will be broken once you remove the original image.

Of course you'll want to test everything carefully in a safe environment before you do any bulk operation on a live site. If it all sounds too difficult or risky, then consider if it's even necessary. Why not just keep two different image fields instead of consolidating them into one?

  • Like 2
Link to comment
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
 Share

×
×
  • Create New...