From 140ce5fa83eb168677b4ffd9147409e1c3c10c4a Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 30 Sep 2020 14:01:49 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#1253 --- .../InputfieldImage/InputfieldImage.module | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module index 8f2c6c0f..2cf0116c 100755 --- a/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module +++ b/wire/modules/Inputfield/InputfieldImage/InputfieldImage.module @@ -203,19 +203,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu } if(!$renderValueMode && $this->value instanceof Pageimages) { - $page = $this->hasPage; - if(!$page || !$page->id) { - $process = $this->wire('process'); - if($process instanceof WirePageEditor) { - $page = $process->getPage(); - } else { - $page = new NullPage(); - } - } - if(wireClassExists('RepeaterPage')) { - /** @var RepeaterPage $page */ - while(wireInstanceOf($page, 'RepeaterPage')) $page = $page->getForPage(); - } + $page = $this->getRootHasPage(); if($page->id && $this->wire('user')->hasPermission('page-edit-images', $page)) { $modules->get('JqueryUI')->use('modal'); } else { @@ -1243,6 +1231,24 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu return $tooltip; } + /** + * Get the root "hasPage" being edited + * + * @return NullPage|Page + * @since 3.0.168 + * + */ + protected function getRootHasPage() { + $page = $this->hasPage; + if(!$page || !$page->id) { + $process = $this->wire()->process; + $page = $process instanceof WirePageEditor ? $process->getPage() : new NullPage(); + } + if(wireClassExists('RepeaterPage')) { /** @var RepeaterPage $page */ + while(wireInstanceOf($page, 'RepeaterPage')) $page = $page->getForPage(); + } + return $page; + } /** * Build data for the tooltip that appears above the thumbnails @@ -1311,7 +1317,7 @@ class InputfieldImage extends InputfieldFile implements InputfieldItemList, Inpu /** @var Sanitizer $sanitizer */ $sanitizer = $this->wire('sanitizer'); - $page = $this->hasPage; + $page = $this->getRootHasPage(); if($page && $page->id) { if(!$this->wire()->user->hasPermission('page-edit-images', $page)) $this->useImageEditor = 0;