> $items Ordered condition and action nodes. * * @since 0.1.0 */ public static function layout_step( string $prefix, string $trigger_id, string $trigger_kind, array $items ): ActionStep { $origin_x = 72; $origin_y = 36; $gap = 156; $nodes = [ [ 'id' => $prefix . '-t', 'kind' => 'trigger', 'x' => $origin_x, 'y' => $origin_y, 'triggerId' => $trigger_id, 'triggerKind' => $trigger_kind, ], ]; $edges = []; $prev = $prefix . '-t'; $port = 'next'; $i = 0; foreach ( $items as $item ) { ++$i; $id = $prefix . '-n' . (string) $i; $kind = isset( $item['kind'] ) ? (string) $item['kind'] : 'action'; $y = $origin_y + ( $i * $gap ); if ( 'condition' === $kind ) { $nodes[] = [ 'id' => $id, 'kind' => 'condition', 'x' => $origin_x, 'y' => $y, 'identifier' => (string) ( $item['identifier'] ?? '' ), 'config' => isset( $item['config'] ) && is_array( $item['config'] ) ? $item['config'] : [], ]; $edges[] = [ 'id' => $prefix . '-e' . (string) $i, 'from' => $prev, 'to' => $id, 'port' => $port, ]; $prev = $id; $port = 'true'; continue; } $nodes[] = [ 'id' => $id, 'kind' => 'action', 'x' => $origin_x, 'y' => $y, 'type' => (string) ( $item['type'] ?? 'log_activity' ), 'delayMinutes' => (int) ( $item['delay_minutes'] ?? 0 ), 'contextMode' => (string) ( $item['context_mode'] ?? ContextMode::Snapshot->value ), 'recipient' => (string) ( $item['recipient'] ?? 'customer' ), 'intent' => (string) ( $item['intent'] ?? 'transactional' ), 'config' => isset( $item['config'] ) && is_array( $item['config'] ) ? $item['config'] : [], ]; $edges[] = [ 'id' => $prefix . '-e' . (string) $i, 'from' => $prev, 'to' => $id, 'port' => $port, ]; $prev = $id; $port = 'next'; } return new ActionStep( 'flow_layout', [ 'v' => 1, 'nodes' => $nodes, 'edges' => $edges, ], 0, 0, ContextMode::Snapshot ); } }