mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 01:55:01 +00:00
Add duplicate workflow prevention in MetadataExtractor
Integrate DuplicateEntityWorkflowFinder to prevent creating workflows for entities with existing opened or positive final workflows. Updated EntityWorkflowVoter to implement the same check before allowing creation. Removed unnecessary blank workflow parameter from Twig template.
This commit is contained in:
@@ -19,20 +19,33 @@ use Symfony\Component\Workflow\WorkflowInterface;
|
||||
|
||||
class MetadataExtractor
|
||||
{
|
||||
public function __construct(private readonly Registry $registry, private readonly TranslatableStringHelperInterface $translatableStringHelper) {}
|
||||
public function __construct(
|
||||
private readonly Registry $registry,
|
||||
private readonly TranslatableStringHelperInterface $translatableStringHelper,
|
||||
private readonly DuplicateEntityWorkflowFinder $duplicateEntityWorkflowFinder,
|
||||
) {}
|
||||
|
||||
public function availableWorkflowFor(string $relatedEntityClass, ?int $relatedEntityId = 0): array
|
||||
{
|
||||
$blankEntityWorkflow = new EntityWorkflow();
|
||||
$blankEntityWorkflow
|
||||
->setRelatedEntityId($relatedEntityId)
|
||||
->setRelatedEntityClass($relatedEntityClass);
|
||||
->setRelatedEntityClass($relatedEntityClass)
|
||||
;
|
||||
|
||||
// build the list of available workflows, and extract their names from metadata
|
||||
$workflows = $this->registry->all($blankEntityWorkflow);
|
||||
$workflowsList = [];
|
||||
|
||||
foreach ($workflows as $workflow) {
|
||||
// shortcut: we must not be able to create a new workflow if there are already created workflows,
|
||||
// so, we find if there are workflows opened or final positive for the same entity
|
||||
$blankEntityWorkflow->setWorkflowName($workflow->getName());
|
||||
if ($this->duplicateEntityWorkflowFinder->hasDuplicateOpenedOrFinalPositiveEntityWorkflow($blankEntityWorkflow)) {
|
||||
// if yes, we skip suggesting workflow
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata = $workflow->getMetadataStore()->getWorkflowMetadata();
|
||||
$text = \array_key_exists('label', $metadata) ?
|
||||
$this->translatableStringHelper->localize($metadata['label']) : $workflow->getName();
|
||||
|
Reference in New Issue
Block a user