From f6a1ea781b928a7e54ce06f06a6b57e2cea82ada Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 31 May 2024 14:33:16 -0400 Subject: [PATCH] Improve support where fields in repeaters (or other embedded types) can have dependencies reference fields outside the repeater by using the "forpage.field_name=..." syntax in teh depedency. For instance, if you want a field in a repeater to only appear if editing a page using template ID 123 then you could use showIf dependency "forpage.template=123". --- wire/core/Field.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wire/core/Field.php b/wire/core/Field.php index 46ed87fe..f2d2bf29 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -1065,7 +1065,13 @@ class Field extends WireData implements Saveable, Exportable { foreach(array('showIf', 'requiredIf') as $depType) { $theIf = $inputfield->getSetting($depType); if(empty($theIf)) continue; - $inputfield->set($depType, preg_replace('/([_.|a-zA-Z0-9]+)([=!%*<>]+)/', '$1' . $contextStr . '$2', $theIf)); + $theIf = preg_replace('/([_.|a-zA-Z0-9]+)([=!%*<>]+)/', '$1' . $contextStr . '$2', $theIf); + if(stripos($theIf, 'forpage.') !== false) { + // de-contextualize if the field name starts with 'forpage.' as used by + // repeaters (or others) referring to page in editor rather than item page + $theIf = preg_replace('/forpage\.([_.|a-z0-9]+)' . $contextStr . '([=!%*<>]+)/i', '$1$2', $theIf); + } + $inputfield->set($depType, $theIf); } }