civi.afform.sort.prefill¶
Summary¶
This Symfony event gathers dependencies between entities on an Afform prior to loading and prefilling their data. It allows developers to specify which entities depend on other entities so that prerequisites (such as parents in a relationship) are loaded first.
Definition¶
This event is dispatched via the Symfony EventDispatcher during Afform::prefill.
public static function onAfformSortPrefill(\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\Prefill- Returns the active prefill API action.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 processed first.getSorted():string[]- Returns the topologically sorted array of entity names.
Availability¶
- Available since CiviCRM 5.57
Example¶
use Civi\Afform\Event\AfformEntitySortEvent;
public static function onAfformSortPrefill(AfformEntitySortEvent $event): void {
// Ensure Individual2 is prefilled after Individual1
$event->addDependency('Individual2', 'Individual1');
}