Skip to content
Snippets Groups Projects
Commit ea283c02 authored by Steve Wirt's avatar Steve Wirt
Browse files

Issue #3384887: Diagram: Workflow Transition labels with braces can break Mermaid Syntax

parent 6f1a8e30
No related branches found
No related tags found
No related merge requests found
......@@ -45,14 +45,14 @@ class WorkflowDiagramController extends ControllerBase {
/**
* The request stack.
*
* @var Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* WorkflowTypeManager.
*
* @var Drupal\workflows\WorkflowTypeManager
* @var \Drupal\workflows\WorkflowTypeManager
*/
protected $workFlowTypeManager;
......@@ -63,9 +63,9 @@ class WorkflowDiagramController extends ControllerBase {
* The EntityTypeManagerInterface service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The Renderer service.
* @param Symfony\Component\HttpFoundation\RequestStack $request
* @param \Symfony\Component\HttpFoundation\RequestStack $request
* The Request service.
* @param Drupal\workflows\WorkflowTypeManager|null $workflow_type_manager
* @param \Drupal\workflows\WorkflowTypeManager|null $workflow_type_manager
* Workflow type manager.
*/
public function __construct(
......@@ -169,7 +169,7 @@ class WorkflowDiagramController extends ControllerBase {
}
elseif (!empty($transition_id) && $transition_id !== 'all') {
$transitions = $this->getWorkflowTransitions($workflow, $transition_id);
/** @var Drupal\workflows\Transition $transition*/
/** @var \Drupal\workflows\Transition $transition*/
$transition = reset($transitions);
$transition_name = $transition->label();
$vars = [
......@@ -217,13 +217,13 @@ class WorkflowDiagramController extends ControllerBase {
// Build the Transitions.
foreach ($transitions as $transition_id => $transition) {
/** @var Drupal\workflows\Transition $transition */
/** @var \Drupal\workflows\Transition $transition */
$to = $transition->to();
$to_id = $to->id();
$froms = $transition->from();
foreach ($froms as $from) {
$from_id = $from->id();
$output .= " {$from_id} -->|{$transition->label()}|{$to_id}\n";
$output .= $this->makeArrow($from_id, $to_id, $transition->label());
}
}
}
......@@ -246,13 +246,13 @@ class WorkflowDiagramController extends ControllerBase {
$output .= " {$this->t('Before')} -.- {$this->t('After')}\n";
// Build the Transitions.
foreach ($transitions as $transition_id => $transition) {
/** @var Drupal\workflows\Transition $transition */
/** @var \Drupal\workflows\Transition $transition */
$to = $transition->to();
$to_id = $to->id();
$to_id = $to->id() . '_after';
$froms = $transition->from();
foreach ($froms as $from) {
$from_id = $from->id();
$output .= " {$from_id}_before -->|{$transition->label()}|{$to_id}_after\n";
$from_id = $from->id() . '_before';
$output .= $this->makeArrow($from_id, $to_id, $transition->label());
}
}
}
......@@ -289,7 +289,7 @@ class WorkflowDiagramController extends ControllerBase {
* @param string $workflow_id
* The workflow id.
*
* @return Drupal\workflows\Entity\Workflow|null
* @return \Drupal\workflows\Entity\Workflow|null
* The workflow object or null if not found.
*/
protected function getWorkflow($workflow_type, $workflow_id) {
......
......@@ -22,7 +22,7 @@ trait MermaidTrait {
$item = '';
if (!empty($content)) {
$wrapper = $this->getShape($shape);
$item = "{$wrapper[0]}{$content}{$wrapper[1]}";
$item = "{$wrapper[0]}\"{$content}\"{$wrapper[1]}";
}
return $item;
}
......@@ -88,4 +88,24 @@ trait MermaidTrait {
return $subgraph;
}
/**
* Creates an arrow connector with optional label.
*
* @param string $from_id
* The id for the shape at the tail of the arrow.
* @param string $to_id
* The id for the shape at the head of the arrow.
* @param string $label
* The optional label for the arrow.
*
* @return string
* The mermaid code for an arrow connector.
*/
public function makeArrow(string $from_id, string $to_id, string $label = ''):string {
if (empty($label)) {
return " {$from_id} --> {$to_id}\n";
}
return " {$from_id} -->|\"$label\"|{$to_id}\n";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment