mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Fix issue processwire/processwire-issues#1255 where rename didn't work for 1-image allowed image field, plus a related issue where rename of image could leave some variations unrenamed.
This commit is contained in:
@@ -205,8 +205,7 @@ class PagefileExtra extends WireData {
|
||||
*
|
||||
*/
|
||||
public function rename() {
|
||||
if(!$this->exists()) return false;
|
||||
if(!$this->filenamePrevious) return false;
|
||||
if(!$this->filenamePrevious || !is_readable($this->filenamePrevious)) return false;
|
||||
return $this->wire('files')->rename($this->filenamePrevious, $this->filename());
|
||||
}
|
||||
|
||||
|
@@ -1755,6 +1755,39 @@ class Pageimage extends Pagefile {
|
||||
return $extras;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this file
|
||||
*
|
||||
* Remember to follow this up with a `$page->save()` for the page that the file lives on.
|
||||
*
|
||||
* #pw-group-manipulation
|
||||
*
|
||||
* @param string $basename New name to use. Must be just the file basename (no path).
|
||||
* @return string|bool Returns new name (basename) on success, or boolean false if rename failed.
|
||||
*
|
||||
*/
|
||||
public function rename($basename) {
|
||||
|
||||
$variations = $this->getVariations();
|
||||
$oldBasename = $this->basename;
|
||||
$newBasename = parent::rename($basename);
|
||||
|
||||
if($newBasename === false) return false;
|
||||
|
||||
$ext = '.' . $this->ext();
|
||||
$oldName = basename($oldBasename, $ext);
|
||||
$newName = basename($newBasename, $ext);
|
||||
|
||||
foreach($variations as $pageimage) {
|
||||
/** @var Pageimage $pageimage */
|
||||
if(strpos($pageimage->basename, $oldName) !== 0) continue;
|
||||
$newVariationName = $newName . substr($pageimage->basename, strlen($oldName));
|
||||
$pageimage->rename($newVariationName);
|
||||
}
|
||||
|
||||
return $newBasename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace file with another
|
||||
*
|
||||
|
@@ -1022,8 +1022,9 @@ function InputfieldImage($) {
|
||||
var $span = $(this).children('span');
|
||||
var $input = $span.closest('.gridImage, .InputfieldImageEdit').find('.InputfieldFileRename');
|
||||
var $list = $span.closest('.gridImages');
|
||||
var sortable = $list.hasClass('ui-sortable');
|
||||
|
||||
$list.sortable('disable');
|
||||
if(sortable) $list.sortable('disable');
|
||||
$input.val($span.text());
|
||||
|
||||
$span.on('keypress', function(e) {
|
||||
@@ -1049,7 +1050,7 @@ function InputfieldImage($) {
|
||||
//console.log('changed to: ' + val);
|
||||
}
|
||||
$span.off('keypress');
|
||||
$list.sortable('enable');
|
||||
if(sortable) $list.sortable('enable');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@@ -54,7 +54,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
return array(
|
||||
'title' => __('Images', __FILE__), // Module Title
|
||||
'summary' => __('One or more image uploads (sortable)', __FILE__), // Module Summary
|
||||
'version' => 123,
|
||||
'version' => 124,
|
||||
'permanent' => true,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user