mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
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".
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user