mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Add allowProcessInput() hook to InputfieldWrapper class. This enables hooks to control whether a given Inputfield can be excluded from input processing at runtime
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*
|
||||
* @method string renderInputfield(Inputfield $inputfield, $renderValueMode = false) #pw-group-output
|
||||
* @method Inputfield new($typeName, $name = '', $label = '', array $settings = []) #pw-group-manipulation
|
||||
* @method bool allowProcessInput(Inputfield $inputfield) Allow Inputfield to have input processed? (3.0.207+) #pw-internal
|
||||
*
|
||||
* @property InputfieldAsmSelect $InputfieldAsmSelect
|
||||
* @property InputfieldButton $InputfieldButton
|
||||
@@ -1159,12 +1160,17 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
||||
*/
|
||||
public function ___processInput(WireInputData $input) {
|
||||
|
||||
if(!$this->children) return $this;
|
||||
if(!$this->children) return $this;
|
||||
|
||||
$hasHook = $this->isHooked('InputfieldWrapper::allowProcessInput()');
|
||||
|
||||
foreach($this->children() as $child) {
|
||||
/** @var Inputfield $child */
|
||||
|
||||
// skip over the field if it is not processable
|
||||
// skip over the inputfield if hook tells us so
|
||||
if($hasHook && !$this->allowProcessInput($child)) continue;
|
||||
|
||||
// skip over the inputfield if it is not processable
|
||||
if(!$this->isProcessable($child)) continue;
|
||||
|
||||
// pass along the dependencies value to child wrappers
|
||||
@@ -1258,6 +1264,25 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow input to be processed for given Inputfield? (for hooks)
|
||||
*
|
||||
* IMPORTANT: This method is not called unless it is hooked! Descending classes
|
||||
* should instead implement the isProcessable() method (when needed) and be sure to
|
||||
* call the parent isProcessable() method too.
|
||||
*
|
||||
* #pw-hooker
|
||||
* #pw-internal
|
||||
*
|
||||
* @param Inputfield $inputfield
|
||||
* @return bool
|
||||
* @since 3.0.207
|
||||
*
|
||||
*/
|
||||
public function ___allowProcessInput(Inputfield $inputfield) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if all children are empty, or false if one or more is populated
|
||||
*
|
||||
|
Reference in New Issue
Block a user