civi.afform.sort.submit¶
Summary¶
This Symfony event gathers dependencies between entities on an Afform prior to saving submitted records. It allows developers to specify which entities depend on other entities so that parent records (e.g. Contacts) are saved first and their resulting IDs can be referenced by dependent records (e.g. Activities, Relationships, Contributions).
Definition¶
This event is dispatched via the Symfony EventDispatcher during Afform::submit.
public static function onAfformSortSubmit(\Civi\Afform\Event\AfformEntitySortEvent $event): void
Parameters¶
\Civi\Afform\Event\AfformEntitySortEvent $event
Event Methods¶
getAfform():array- Returns the main Afform configuration array.getFormDataModel():\Civi\Afform\FormDataModel- Returns the form data model instance.getApiRequest():\Civi\Api4\Action\Afform\Submit- Returns the active submit API action.getEntityValues():array- Returns submitted entity records being processed.addEntity(string $entityName):void- Adds an entity name to the list of sortable graph nodes.addDependency(string $dependentEntity, string $dependsOnEntity):void- Declares that$dependentEntityrequires$dependsOnEntityto be saved first.getSorted():string[]- Returns the topologically sorted array of entity names.
Availability¶
- Available since CiviCRM 6.17
- Method
getEntityValues()added in CiviCRM 6.20
Example¶
use Civi\Afform\Event\AfformEntitySortEvent;
public static function onAfformSortSubmit(AfformEntitySortEvent $event): void {
// Ensure custom entity CustomRecord1 is saved after Contact1
$event->addDependency('CustomRecord1', 'Contact1');
}