@@ -463,32 +463,68 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
463463 foreach ($ config ['workflows ' ] as $ name => $ workflow ) {
464464 $ type = $ workflow ['type ' ];
465465
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
466482 $ transitions = array ();
483+ $ transitionsMetadataDefinition = new Definition (\SplObjectStorage::class);
467484 foreach ($ workflow ['transitions ' ] as $ transition ) {
468485 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+ }
470494 } elseif ('state_machine ' === $ type ) {
471495 foreach ($ transition ['from ' ] as $ from ) {
472496 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+ }
474505 }
475506 }
476507 }
477508 }
509+ $ metadataStoreDefinition ->replaceArgument (2 , $ transitionsMetadataDefinition );
510+
511+ // Create places
512+ $ places = array_map (function (array $ place ) {
513+ return $ place ['name ' ];
514+ }, $ workflow ['places ' ]);
478515
479516 // Create a Definition
480517 $ definitionDefinition = new Definition (Workflow \Definition::class);
481518 $ definitionDefinition ->setPublic (false );
482- $ definitionDefinition ->addArgument ($ workflow [ ' places ' ] );
519+ $ definitionDefinition ->addArgument ($ places );
483520 $ definitionDefinition ->addArgument ($ transitions );
521+ $ definitionDefinition ->addArgument ($ workflow ['initial_place ' ] ?? null );
522+ $ definitionDefinition ->addArgument ($ metadataStoreDefinition );
484523 $ definitionDefinition ->addTag ('workflow.definition ' , array (
485524 'name ' => $ name ,
486525 'type ' => $ type ,
487526 'marking_store ' => isset ($ workflow ['marking_store ' ]['type ' ]) ? $ workflow ['marking_store ' ]['type ' ] : null ,
488527 ));
489- if (isset ($ workflow ['initial_place ' ])) {
490- $ definitionDefinition ->addArgument ($ workflow ['initial_place ' ]);
491- }
492528
493529 // Create MarkingStore
494530 if (isset ($ workflow ['marking_store ' ]['type ' ])) {
0 commit comments