@@ -463,32 +463,68 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
463
463
foreach ($ config ['workflows ' ] as $ name => $ workflow ) {
464
464
$ type = $ workflow ['type ' ];
465
465
466
+ // Process Metadata (workflow + places (transition is done in the "create transition" block))
467
+ $ metadataStoreDefinition = new Definition (Workflow \Metadata \InMemoryMetadataStore::class, array (null , null , null ));
468
+ if ($ workflow ['metadata ' ]) {
469
+ $ metadataStoreDefinition ->replaceArgument (0 , new Definition (Workflow \Metadata \MetadataBag::class, array ($ workflow ['metadata ' ])));
470
+ }
471
+ $ placesMetadata = array ();
472
+ foreach ($ workflow ['places ' ] as $ place ) {
473
+ if ($ place ['metadata ' ]) {
474
+ $ placesMetadata [$ place ['name ' ]] = new Definition (Workflow \Metadata \MetadataBag::class, array ($ place ['metadata ' ]));
475
+ }
476
+ }
477
+ if ($ placesMetadata ) {
478
+ $ metadataStoreDefinition ->replaceArgument (1 , $ placesMetadata );
479
+ }
480
+
481
+ // Create transitions
466
482
$ transitions = array ();
483
+ $ transitionsMetadataDefinition = new Definition (\SplObjectStorage::class);
467
484
foreach ($ workflow ['transitions ' ] as $ transition ) {
468
485
if ('workflow ' === $ type ) {
469
- $ transitions [] = new Definition (Workflow \Transition::class, array ($ transition ['name ' ], $ transition ['from ' ], $ transition ['to ' ]));
486
+ $ transitionDefinition = new Definition (Workflow \Transition::class, array ($ transition ['name ' ], $ transition ['from ' ], $ transition ['to ' ]));
487
+ $ transitions [] = $ transitionDefinition ;
488
+ if ($ transition ['metadata ' ]) {
489
+ $ transitionsMetadataDefinition ->addMethodCall ('attach ' , array (
490
+ $ transitionDefinition ,
491
+ new Definition (Workflow \Metadata \MetadataBag::class, array ($ transition ['metadata ' ])),
492
+ ));
493
+ }
470
494
} elseif ('state_machine ' === $ type ) {
471
495
foreach ($ transition ['from ' ] as $ from ) {
472
496
foreach ($ transition ['to ' ] as $ to ) {
473
- $ transitions [] = new Definition (Workflow \Transition::class, array ($ transition ['name ' ], $ from , $ to ));
497
+ $ transitionDefinition = new Definition (Workflow \Transition::class, array ($ transition ['name ' ], $ from , $ to ));
498
+ $ transitions [] = $ transitionDefinition ;
499
+ if ($ transition ['metadata ' ]) {
500
+ $ transitionsMetadataDefinition ->addMethodCall ('attach ' , array (
501
+ $ transitionDefinition ,
502
+ new Definition (Workflow \Metadata \MetadataBag::class, array ($ transition ['metadata ' ])),
503
+ ));
504
+ }
474
505
}
475
506
}
476
507
}
477
508
}
509
+ $ metadataStoreDefinition ->replaceArgument (2 , $ transitionsMetadataDefinition );
510
+
511
+ // Create places
512
+ $ places = array_map (function (array $ place ) {
513
+ return $ place ['name ' ];
514
+ }, $ workflow ['places ' ]);
478
515
479
516
// Create a Definition
480
517
$ definitionDefinition = new Definition (Workflow \Definition::class);
481
518
$ definitionDefinition ->setPublic (false );
482
- $ definitionDefinition ->addArgument ($ workflow [ ' places ' ] );
519
+ $ definitionDefinition ->addArgument ($ places );
483
520
$ definitionDefinition ->addArgument ($ transitions );
521
+ $ definitionDefinition ->addArgument ($ workflow ['initial_place ' ] ?? null );
522
+ $ definitionDefinition ->addArgument ($ metadataStoreDefinition );
484
523
$ definitionDefinition ->addTag ('workflow.definition ' , array (
485
524
'name ' => $ name ,
486
525
'type ' => $ type ,
487
526
'marking_store ' => isset ($ workflow ['marking_store ' ]['type ' ]) ? $ workflow ['marking_store ' ]['type ' ] : null ,
488
527
));
489
- if (isset ($ workflow ['initial_place ' ])) {
490
- $ definitionDefinition ->addArgument ($ workflow ['initial_place ' ]);
491
- }
492
528
493
529
// Create MarkingStore
494
530
if (isset ($ workflow ['marking_store ' ]['type ' ])) {
0 commit comments