Although on the basic level models can perform "CRUD" operations (create, read, update and delete), in reality there are many other actions.
Currently you have to create method inside a model, but it's hard for the other components to discover which methods are safe to execute.
I propose we implement hook getActions that would return array of special action objects. So your model Package could be like this:
$this->addHook('getActions', function($m) {
return [
'delivered' => new Action("Signed for Delivery", function($m){
return $m->save('delivered', true);
})
]
});
Second argument is optional and if not specified then $m->delivered() is called. Class Action could be initially quite simple, but then we can add all sorts of properties to it - is at a dangerous action? What arguments are required? etc.
This action would be safe to exported through UI or API frameworks as a button or a POST end-point.
Although on the basic level models can perform "CRUD" operations (create, read, update and delete), in reality there are many other actions.
Currently you have to create method inside a model, but it's hard for the other components to discover which methods are safe to execute.
I propose we implement hook
getActionsthat would return array of special action objects. So your modelPackagecould be like this:Second argument is optional and if not specified then $m->delivered() is called. Class
Actioncould be initially quite simple, but then we can add all sorts of properties to it - is at a dangerous action? What arguments are required? etc.This action would be safe to exported through UI or API frameworks as a button or a POST end-point.