mirror of
https://github.com/processwire/processwire.git
synced 2025-08-21 22:06:12 +02:00
Add ProcessField detection for invalid Page field showIf/requiredIf dependencies per processwire/processwire-issues#509
This commit is contained in:
@@ -1837,6 +1837,10 @@ class ProcessField extends Process implements ConfigurableModule {
|
|||||||
if(!$this->isAllowedName($value)) continue;
|
if(!$this->isAllowedName($value)) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(($name == 'showIf' || $name == 'requiredIf') && strlen($value)) {
|
||||||
|
$this->checkInputfieldDependencySetting($inputfield);
|
||||||
|
}
|
||||||
|
|
||||||
$this->field->set($name, $value);
|
$this->field->set($name, $value);
|
||||||
|
|
||||||
// account for languages, if used
|
// account for languages, if used
|
||||||
@@ -1869,6 +1873,36 @@ class ProcessField extends Process implements ConfigurableModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check a showIf or requiredIf setting for potential problems
|
||||||
|
*
|
||||||
|
* @param Inputfield $inputfield Inputfield containing the setting (showIf/requiredIf)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function checkInputfieldDependencySetting(Inputfield $inputfield) {
|
||||||
|
$label = sprintf($this->_('Error in setting “%s”'), $inputfield->getSetting('label'));
|
||||||
|
$value = $inputfield->attr('value');
|
||||||
|
$valueLabel = ' ' . sprintf($this->_('(you specified “%s”)'), $value);
|
||||||
|
if(empty($value)) return;
|
||||||
|
try {
|
||||||
|
$selectors = new Selectors($value);
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$this->error("$label - " . $this->_('Unable to validate') . $valueLabel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach($selectors as $selector) {
|
||||||
|
foreach($selector->fields() as $f) {
|
||||||
|
if(strpos($f, '.')) continue;
|
||||||
|
if(!strlen($selector->value())) continue;
|
||||||
|
$f = $this->wire('fields')->get($f);
|
||||||
|
if(!$f || !$f->type instanceof FieldtypePage) continue;
|
||||||
|
$v = implode('', $selector->values());
|
||||||
|
if(ctype_digit("$v")) continue; // validates
|
||||||
|
$this->error("$label - " . $this->_('This will not work because values must be page IDs') . $valueLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the submitted checkboxes from the "Overrides" tab
|
* Saves the submitted checkboxes from the "Overrides" tab
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user