mirror of
https://github.com/processwire/processwire.git
synced 2025-08-25 15:51:37 +02:00
Add renderOrProcessReady hook to InputfieldForm
This commit is contained in:
@@ -3,17 +3,20 @@
|
|||||||
/**
|
/**
|
||||||
* InputfieldForm: An Inputfield for containing form elements
|
* InputfieldForm: An Inputfield for containing form elements
|
||||||
*
|
*
|
||||||
|
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||||
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @property string $prependMarkup Optional markup to prepend to the form output
|
* @property string $prependMarkup Optional markup to prepend to the form output
|
||||||
* @property string $appendMarkup Optional markup to append to the form output
|
* @property string $appendMarkup Optional markup to append to the form output
|
||||||
* @property bool $protectCSRF Set to false to disable automatic CSRF protection
|
* @property bool $protectCSRF Set to false to disable automatic CSRF protection
|
||||||
* @property int $columnWidthSpacing Optionally set the column width spacing (pixels)
|
* @property int $columnWidthSpacing Optionally set the column width spacing (pixels)
|
||||||
* @property string $description Optionally set a description headline for the form
|
* @property string $description Optionally set a description headline for the form
|
||||||
* @property string $confirmText Confirmation text that precedes list of changes (when class InputfieldFormConfirm is
|
* @property string $confirmText Confirmation text that precedes list of changes when class InputfieldFormConfirm is active
|
||||||
* active)
|
|
||||||
* @property string $method Form method attribute (default="post")
|
* @property string $method Form method attribute (default="post")
|
||||||
* @property string $action Form action attribute (default="./")
|
* @property string $action Form action attribute (default="./")
|
||||||
*
|
*
|
||||||
|
* @method void renderOrProcessReady($type) Hook called before form render or process (3.0.171+)
|
||||||
|
*
|
||||||
* Optional classes:
|
* Optional classes:
|
||||||
* =================
|
* =================
|
||||||
* InputfieldFormNoHeights: tells it not to worry about lining up all columns vertically.
|
* InputfieldFormNoHeights: tells it not to worry about lining up all columns vertically.
|
||||||
@@ -77,6 +80,18 @@ class InputfieldForm extends InputfieldWrapper {
|
|||||||
|
|
||||||
const debug = false; // set to true to enable debug mode for field dependencies
|
const debug = false; // set to true to enable debug mode for field dependencies
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WireInputData provided to processInput() method
|
||||||
|
*
|
||||||
|
* @var WireInputData|null
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected $_processInputData = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->set('protectCSRF', true);
|
$this->set('protectCSRF', true);
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -88,12 +103,16 @@ class InputfieldForm extends InputfieldWrapper {
|
|||||||
$this->set('confirmText', $this->_('There are unsaved changes:'));
|
$this->set('confirmText', $this->_('There are unsaved changes:'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function debugNote($note) {
|
/**
|
||||||
if(self::debug) $this->message($note);
|
* Render form
|
||||||
}
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function ___render() {
|
public function ___render() {
|
||||||
|
|
||||||
|
if($this->hasHook('renderOrProcessReady()')) $this->renderOrProcessReady('render');
|
||||||
|
|
||||||
$markup = self::getMarkup();
|
$markup = self::getMarkup();
|
||||||
$classes = self::getClasses();
|
$classes = self::getClasses();
|
||||||
if(!empty($classes['form'])) $this->addClass($classes['form']);
|
if(!empty($classes['form'])) $this->addClass($classes['form']);
|
||||||
@@ -149,10 +168,24 @@ class InputfieldForm extends InputfieldWrapper {
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process input
|
||||||
|
*
|
||||||
|
* @param WireInputData $input
|
||||||
|
* @return InputfieldWrapper
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function ___processInput(WireInputData $input) {
|
public function ___processInput(WireInputData $input) {
|
||||||
|
|
||||||
|
$this->_processInputData = $input;
|
||||||
|
if($this->hasHook('renderOrProcessReady()')) $this->renderOrProcessReady('process');
|
||||||
|
|
||||||
$this->getErrors(true); // reset
|
$this->getErrors(true); // reset
|
||||||
if($this->getSetting('protectCSRF') && $this->attr('method') == 'post') $this->wire('session')->CSRF->validate(); // throws exception if invalid
|
|
||||||
|
if($this->getSetting('protectCSRF') && strtolower($this->attr('method')) === 'post') {
|
||||||
|
$this->wire()->session->CSRF->validate(); // throws exception if invalid
|
||||||
|
}
|
||||||
|
|
||||||
$result = parent::___processInput($input);
|
$result = parent::___processInput($input);
|
||||||
|
|
||||||
$delayedChildren = $this->_getDelayedChildren(true);
|
$delayedChildren = $this->_getDelayedChildren(true);
|
||||||
@@ -545,5 +578,35 @@ class InputfieldForm extends InputfieldWrapper {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For internal debugging purposes
|
||||||
|
*
|
||||||
|
* @param $note
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function debugNote($note) {
|
||||||
|
if(self::debug) $this->message($note);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return WireInputData provided to processInput() method or null if not yet applicable
|
||||||
|
*
|
||||||
|
* @return WireInputData|null
|
||||||
|
* @since 3.0.171
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getInput() {
|
||||||
|
return $this->_processInputData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook called right before form is rendered or processed
|
||||||
|
*
|
||||||
|
* @param string $type One of 'render' or 'process'
|
||||||
|
* @since 3.0.171
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function ___renderOrProcessReady($type) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user