mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
mvc - add setBaseHook() to ApiMutableModelControllerBase controller implementation, similar to setActionHook().
Since setBase/addBase need a field to message errors on, its likely better to throw an exception when not able to complete the request in full (and data may not be saved). Usage examples include writing data in other fields not being offered by the gui (for example encode data base64) or autogenerated content as default, volatile model fields can be used to make sure the hook is able to process the non-persistent data (which can still be validated separately).
This commit is contained in:
parent
5db37c89ec
commit
0c39b0a698
@ -296,6 +296,18 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to be overridden if the controller is to take an action when
|
||||
* setBase/addBase is called. This hook is called after a model has been
|
||||
* constructed and validated but before it serialized to the configuration
|
||||
* and written to disk
|
||||
* @throws UserException when action is not possible (and save should be aborted)
|
||||
*/
|
||||
protected function setBaseHook($node)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update model settings
|
||||
* @return array status / validation errors
|
||||
@ -409,6 +421,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
|
||||
$result = $this->validate($node, $post_field);
|
||||
|
||||
if (empty($result['validations'])) {
|
||||
$this->setBaseHook($node);
|
||||
// save config if validated correctly
|
||||
$this->save(false, true);
|
||||
$result = array(
|
||||
@ -492,6 +505,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
|
||||
}
|
||||
$result = $this->validate($node, $post_field, true);
|
||||
if (empty($result['validations'])) {
|
||||
$this->setBaseHook($node);
|
||||
// save config if validated correctly
|
||||
$this->save(false, true);
|
||||
$result = ["result" => "saved"];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user