Define User Action
UI Integration
Arguments
Crud integration
What are User Actions?

Since the early version ATK UI was about building generic UI capable of automatically read information about model Fields and visualising them correctly. Version 2.0 introduces support for "Actions" which can be declared in Data layer and can use generic UI for visualising and triggering. Models of Agile Data has always supported 3 basic actions: "save" (for new and existing records) and "delete". Historically any other interaction required tinkering with UI layer. Now ATK implements a generic support for arbitrary actions and then re-implements "save", "delete" and "add" on top.

This enables developer to easily add more actions in the Data layers and have the rest of ATK recognise and respect those actions. Actions can be added into the model just like you are adding fields:

$country = new Country($owner->getApp()->db);

$country->addUserAction('send_message');

Once defied - actions will be visualised in the Form, Grid, Crud and CardDeck. Additionally add-ons will recognise your actions - for example 'Login' add-on introduces ACL system capable of enabling/disabling fields or actions on per-user basis.

Any actions you define will automatically appear in the UI. This is consistent with your field definitions. You can also "disable" or mark actions as "system". When action is executed, the response will appear to the user as a toast message, but this can also be customised.

$country = new Country($owner->getApp()->db);

$country->addUserAction('send_message', static function (Country $entity) {
    return 'Sent to ' . $entity->get($entity->fieldName()->name);
});
$country = $country->loadAny();

$card = Card::addTo($owner);
$card->setModel($country, [$country->fieldName()->iso]);
$card->addClickAction($country->getModel()->getUserAction('send_message'));
Afghanistan
AF
Send Message