mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
Add feature request processwire/processwire-requests#520 - ability do disable (hide) image items in a multiple image field
This commit is contained in:
@@ -1476,6 +1476,28 @@ class Pagefile extends WireData implements WireArrayItem {
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set hidden state of this file
|
||||
*
|
||||
* Files that are hidden do not appear in the formatted field value,
|
||||
* but do appear in the unformatted value.
|
||||
*
|
||||
* @param bool|null $set
|
||||
* @since 3.0.237
|
||||
*
|
||||
*/
|
||||
public function hidden($set = null) {
|
||||
$value = (bool) $this->filedata('_hide');
|
||||
if($set === null || $set === $value) return $value;
|
||||
if($set === false) {
|
||||
$this->filedata(false, '_hide');
|
||||
} else if($set === true) {
|
||||
$this->filedata('_hide', true);
|
||||
} else {
|
||||
throw new WireException('Invalid arg for Pagefile::hidden(arg)');
|
||||
}
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that isset() and empty() work for dynamic class properties
|
||||
|
@@ -730,7 +730,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule, Fieldt
|
||||
|
||||
foreach($value as $pagefile) {
|
||||
/** @var Pagefile $pagefile */
|
||||
if($pagefile->isTemp()) $value->removeQuietly($pagefile);
|
||||
if($pagefile->isTemp() || $pagefile->hidden()) $value->removeQuietly($pagefile);
|
||||
}
|
||||
|
||||
$textformatters = $field->get('textformatters');
|
||||
|
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Inputfield for FieldtypeImage fields
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2024 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* Accessible Properties
|
||||
@@ -59,7 +59,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' => 127,
|
||||
'version' => 128,
|
||||
'permanent' => true,
|
||||
);
|
||||
}
|
||||
@@ -145,6 +145,8 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
'drag-drop-in' => $this->_('drag and drop in new images above'),
|
||||
'na' => $this->_('N/A'), // for JS
|
||||
'changes' => $this->_('This images field may have unsaved changes that could be lost after this action. Please save before cropping, or double-click the button proceed anyway.'),
|
||||
'visibility' => $this->_('Visibility'),
|
||||
'hidden' => $this->_('Hidden'),
|
||||
));
|
||||
|
||||
$themeDefaults = array(
|
||||
@@ -325,7 +327,9 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
protected function renderItemWrap($out) {
|
||||
$item = $this->currentItem;
|
||||
$id = $item && !$this->renderValueMode ? " id='file_$item->hash'" : "";
|
||||
return "<li$id class='ImageOuter $this->itemClass'>$out</li>";
|
||||
$class = "ImageOuter $this->itemClass";
|
||||
if($item->hidden()) $class .= ' InputfieldFileItemHidden';
|
||||
return "<li$id class='$class'>$out</li>";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -659,6 +663,11 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
if($extra->exists()) $fileStats .= " • $extra->filesizeStr $name ($extra->savingsPct)";
|
||||
}
|
||||
|
||||
if($pagefile->hidden()) {
|
||||
$fileStats .= ' ' . wireIconMarkup('eye-slash') . ' ' .
|
||||
$sanitizer->entities1($this->labels['hidden']);
|
||||
}
|
||||
|
||||
$class = 'gridImage__overflow';
|
||||
if($pagefile->ext() === 'svg') {
|
||||
$class .= ' ' . ($pagefile->ratio < 1 ? 'portrait' : 'landscape');
|
||||
@@ -1024,14 +1033,24 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
'x50' => $this->_('Reduce 50%'),
|
||||
'bw' => $this->_('B&W'), // Black and White
|
||||
'sep' => $this->_('Sepia'),
|
||||
'hide' => $this->_('Hide'),
|
||||
'unhide' => $this->_('Unhide'),
|
||||
);
|
||||
|
||||
$actions = array(
|
||||
'dup' => $labels['dup'],
|
||||
);
|
||||
$actions = array();
|
||||
|
||||
if($this->maxFiles != 1) {
|
||||
if($pagefile->hidden()) {
|
||||
$actions['unhide'] = $labels['unhide'];
|
||||
} else {
|
||||
$actions['hide'] = $labels['hide'];
|
||||
}
|
||||
}
|
||||
|
||||
if($this->maxFiles && count($pagefile->pagefiles) >= $this->maxFiles) {
|
||||
unset($actions['dup']);
|
||||
// no dup action
|
||||
} else {
|
||||
$actions['dup'] = $labels['dup'];
|
||||
}
|
||||
|
||||
if($pagefile->ext() != 'svg') {
|
||||
@@ -1258,6 +1277,13 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
)
|
||||
);
|
||||
|
||||
if($pagefile->hidden()) {
|
||||
$data[] = array(
|
||||
$this->labels['visibility'],
|
||||
wireIconMarkup('eye-slash') . ' ' . $this->labels['hidden']
|
||||
);
|
||||
}
|
||||
|
||||
if(strlen($pagefile->description)) {
|
||||
$data[] = array(
|
||||
$this->labels['description'],
|
||||
@@ -1413,6 +1439,12 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu
|
||||
// remove focus
|
||||
$pagefile->focus(false);
|
||||
$success = true;
|
||||
} else if($action == 'hide') {
|
||||
$pagefile->hidden(true);
|
||||
$success = true;
|
||||
} else if($action == 'unhide') {
|
||||
$pagefile->hidden(false);
|
||||
$success = true;
|
||||
} else {
|
||||
/** @var ImageSizer $sizer Image sizer actions */
|
||||
$sizer = $this->wire(new ImageSizer($pagefile->filename()));
|
||||
|
@@ -5,7 +5,6 @@ $gridMargin: 0 0.6em 0.6em 0;
|
||||
$itemPadding: 0.4em;
|
||||
$focusPointCircleSize: 40px;
|
||||
|
||||
|
||||
.InputfieldImage {
|
||||
.InputfieldHeader {
|
||||
.InputfieldImageListToggle {
|
||||
@@ -400,6 +399,16 @@ $focusPointCircleSize: 40px;
|
||||
background: rgba($deleteColor, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
&.InputfieldFileItemHidden {
|
||||
border-style: dashed !important;
|
||||
img {
|
||||
opacity: 0.3;
|
||||
}
|
||||
.gridImage__overflow {
|
||||
background-image: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A type of item that appears in a ul.gridImages but is not itself a .gridImage.
|
||||
|
Reference in New Issue
Block a user