From 77c7e401da49509dd1042ab3579184da6c8d5994 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 30 Dec 2022 11:47:45 -0500 Subject: [PATCH] Attempt fix for processwire/processwire-issues#1600 --- .../InputfieldFile/InputfieldFile.module | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module index 61ce26cb..83b2b799 100644 --- a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module +++ b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module @@ -1397,13 +1397,31 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel } $context = ''; - $process = $this->wire()->process; - if($item && $process instanceof WirePageEditor) { - $contextPage = $process->getPage(); - if(wireInstanceOf($contextPage, 'RepeaterPage')) { - $context = "repeater{$contextPage->id}_"; + if($item) { + $hasPage = $this->hasPage; + if($hasPage && wireInstanceOf($hasPage, 'RepeaterPage')) { + if(strpos($this->name, '_repeater') === false) { + // ensures that custom fields are properly namespaced within repeater + // though note that this prevents it from working when editing a repeater + // page directly, independently of its forPage + $context = "repeater{$hasPage->id}_"; + } } + /* + * The following does not work with nested repeaters, fixed by the above, but kept here for reference + $process = $this->wire()->process; + if($item && $process instanceof WirePageEditor) { + $contextPage = $process->getPage(); + if(wireInstanceOf($contextPage, 'RepeaterPage') && strpos($this->name, '_repeater') === false) { + // @var RepeaterPage $contextPage + $forPage = $contextPage->getForPage(); + if($forPage->id) $contextPage = $forPage; + $context = "repeater{$contextPage->id}_"; + } + } + */ } + /** @var Page $page */ $page = $pagefiles->getFieldsPage();