1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-15 03:05:26 +02:00

Update ProcessPageEditImageSelect thumbnail list to use field labels to identify when there are multiple images fields on the page from which you can select images to insert

This commit is contained in:
Ryan Cramer
2021-04-16 13:54:14 -04:00
parent 6a04f1f08f
commit 22e5e3989e
2 changed files with 68 additions and 23 deletions

View File

@@ -36,6 +36,17 @@
opacity: 0.9; opacity: 0.9;
} }
.select_images_field_label {
display: none;
}
#select_images.multifield .select_images_field_label {
display: block;
clear: both;
padding-bottom: 5px;
}
#select_images.multifield > li + li.select_images_field_label {
padding-top: 10px;
}
#selected_image, #selected_image,
#selected_image_container { #selected_image_container {

View File

@@ -440,13 +440,21 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
// get images that are possibly in a repeater // get images that are possibly in a repeater
$repeaterValue = $page->get($field->name); $repeaterValue = $page->get($field->name);
if($repeaterValue instanceof Page) $repeaterValue = array($repeaterValue); if($repeaterValue instanceof Page) $repeaterValue = array($repeaterValue);
if($repeaterValue) foreach($repeaterValue as $p) { if($repeaterValue) {
foreach($repeaterValue as $p) {
$images = $this->getImages($p, $p->fields, $level + 1); $images = $this->getImages($p, $p->fields, $level + 1);
if(!count($images)) continue; if(!count($images)) continue;
foreach($images as $image) {
$parentFields = $image->get('_parentFields');
if(!is_array($parentFields)) $parentFields = array();
array_unshift($parentFields, $field);
$image->setQuietly('_parentFields', $parentFields);
}
$allImages = array_merge($allImages, $images); $allImages = array_merge($allImages, $images);
$numImages += count($images); $numImages += count($images);
$numImageFields++; $numImageFields++;
} }
}
continue; continue;
} }
@@ -463,8 +471,11 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
} }
if(!$level) { if(!$level) {
if(!$numImageFields) $this->message($this->_("There are no image fields on this page. Choose another page to select images from.")); // Message when page has no image fields if(!$numImageFields) {
else if(!$numImages) $this->message($this->_("There are no images present on this page. Upload an image, or select images from another page.")); // Message when page has no images $this->message($this->_("There are no image fields on this page. Choose another page to select images from.")); // Message when page has no image fields
} else if(!$numImages) {
$this->message($this->_("There are no images present on this page. Upload an image, or select images from another page.")); // Message when page has no images
}
} }
return $allImages; return $allImages;
@@ -505,6 +516,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
public function ___execute() { public function ___execute() {
if($this->config->demo) throw new WireException("Sorry, image editing functions are disabled in demo mode"); if($this->config->demo) throw new WireException("Sorry, image editing functions are disabled in demo mode");
if(!$this->page) { if(!$this->page) {
$error = "No page provided"; $error = "No page provided";
$this->error($error); $this->error($error);
@@ -513,19 +525,37 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
if($this->input->get('file')) return $this->executeEdit(); if($this->input->get('file')) return $this->executeEdit();
$sanitizer = $this->wire()->sanitizer;
$modules = $this->wire()->modules;
$images = $this->getImages($this->page, $this->page->fields); $images = $this->getImages($this->page, $this->page->fields);
$out = ''; $out = '';
if(count($images)) { if(count($images)) {
$winwidth = (int) $this->input->get('winwidth'); $winwidth = (int) $this->wire()->input->get('winwidth');
$in = $this->wire('modules')->get('InputfieldImage'); $in = $modules->get('InputfieldImage'); /** @var InputfieldImage $in */
$in->adminThumbs = true; $in->set('adminThumbs', true);
$lastFieldLabel = '';
$numImageFields = 0;
foreach($images as $image) { foreach($images as $image) {
/** @var PageImage $image */
$fieldLabels = array();
$parentFields = $image->get('_parentFields');
if(!is_array($parentFields)) $parentFields = array();
foreach($parentFields as $parentField) {
$fieldLabels[] = $parentField->getLabel();
}
$fieldLabels[] = $image->field->getLabel();
$fieldLabel = implode(' > ', $fieldLabels);
if($fieldLabel != $lastFieldLabel) {
$numImageFields++;
$out .= "\n\t<li class='select_images_field_label detail'>" . $sanitizer->entities($fieldLabel) . "</li>";
}
$lastFieldLabel = $fieldLabel;
if($this->noThumbs) { if($this->noThumbs) {
$width = $image->width(); $width = $image->width();
$alt = $this->wire('sanitizer')->entities1($image->description); $alt = $sanitizer->entities1($image->description);
if($width > $this->maxImageWidth) $width = $this->maxImageWidth; if($width > $this->maxImageWidth) $width = $this->maxImageWidth;
$img = "<img src='$image->URL' width='$width' alt=\"$alt\" />"; $img = "<img src='$image->URL' width='$width' alt=\"$alt\" />";
} else { } else {
@@ -533,22 +563,24 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
$info = $in->getAdminThumb($image); $info = $in->getAdminThumb($image);
$img = $info['markup']; $img = $info['markup'];
} }
$out .= "\n\t<li><a href='./edit?file={$image->page->id},{$image->basename}" . $out .=
"\n\t<li><a href='./edit?file={$image->page->id},{$image->basename}" .
"&amp;modal=1&amp;id={$this->page->id}&amp;winwidth=$winwidth'>$img</a></li>"; "&amp;modal=1&amp;id={$this->page->id}&amp;winwidth=$winwidth'>$img</a></li>";
} }
$class = $this->noThumbs ? "" : "thumbs"; $class = $this->noThumbs ? "" : "thumbs";
if($numImageFields > 1) $class = trim("$class multifield");
$out = "\n<ul id='select_images' class='$class'>$out\n</ul>"; $out = "\n<ul id='select_images' class='$class'>$out\n</ul>";
} }
/** @var InputfieldForm $form */ /** @var InputfieldForm $form */
$form = $this->modules->get("InputfieldForm"); $form = $modules->get("InputfieldForm");
$form->action = "./"; $form->action = "./";
$form->method = "get"; $form->method = "get";
/** @var InputfieldPageListSelect $field */ /** @var InputfieldPageListSelect $field */
$field = $this->modules->get("InputfieldPageListSelect"); $field = $modules->get("InputfieldPageListSelect");
$field->label = $this->_("Images on Page:") . ' ' . $this->page->get("title") . " (" . $this->page->path . ")"; // Headline for page selection, precedes current page title/url $field->label = $this->_("Images on Page:") . ' ' . $this->page->get("title") . " (" . $this->page->path . ")"; // Headline for page selection, precedes current page title/url
$field->description = $this->_("If you would like to select images from another page, select the page below."); // Instruction on how to select another page $field->description = $this->_("If you would like to select images from another page, select the page below."); // Instruction on how to select another page
$field->attr('id+name', 'page_id'); $field->attr('id+name', 'page_id');
@@ -563,19 +595,21 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
if(count($imageFields)) { if(count($imageFields)) {
$imageFieldNames = implode(',', array_keys($imageFields)); $imageFieldNames = implode(',', array_keys($imageFields));
/** @var InputfieldButton $btn */ /** @var InputfieldButton $btn */
$btn = $this->modules->get('InputfieldButton'); $btn = $modules->get('InputfieldButton');
$uploadOnlyMode = "$this->page" === "$this->editorPage" ? 1 : 2; $uploadOnlyMode = "$this->page" === "$this->editorPage" ? 1 : 2;
$btn->href = "../edit/?modal=1&id={$this->page->id}&fields=$imageFieldNames&uploadOnlyMode=$uploadOnlyMode"; $btn->href = "../edit/?modal=1&id={$this->page->id}&fields=$imageFieldNames&uploadOnlyMode=$uploadOnlyMode";
$btn->value = $this->_('Upload Image'); $btn->value = $this->_('Upload Image');
$btn->addClass('upload pw-modal-button pw-modal-button-visible'); $btn->addClass('upload pw-modal-button pw-modal-button-visible');
$btn->icon = 'upload'; $btn->icon = 'upload';
$changes = $this->wire('input')->get('changes'); $changes = $this->wire('input')->get('changes');
if($changes) foreach(explode(',', $changes) as $name) { if($changes) {
$name = $this->wire('sanitizer')->fieldName($name); foreach(explode(',', $changes) as $name) {
$field = $this->wire('fields')->get($name); $name = $sanitizer->fieldName($name);
$field = $this->wire()->fields->get($name);
if(!$field) continue; if(!$field) continue;
$out .= "<script>refreshPageEditField('$name');</script>"; $out .= "<script>refreshPageEditField('$name');</script>";
} }
}
} else $btn = null; } else $btn = null;
$out = $form->render() . $out; $out = $form->render() . $out;