Skip to content

Commit

Permalink
bug #49272 [Workflow] remove new lines from workflow metadata (alexis…
Browse files Browse the repository at this point in the history
…lefebvre)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Workflow] remove new lines from workflow metadata

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #49174
| License       | MIT
| Doc PR        | no

Don't dump new lines in workflow dumps.

Commits
-------

a3062c7 [Workflow] remove new lines from workflow metadata
  • Loading branch information
fabpot committed Feb 20, 2023
2 parents 490fa24 + a3062c7 commit 6627291
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/Dumper/MermaidDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private function styleStatemachineTransition(
string $transitionLabel,
array $transitionMeta
): array {
$transitionOutput = [sprintf('%s-->|%s|%s', $from, $this->escape($transitionLabel), $to)];
$transitionOutput = [sprintf('%s-->|%s|%s', $from, str_replace("\n", ' ', $this->escape($transitionLabel)), $to)];

$linkStyle = $this->styleLink($transitionMeta);
if ('' !== $linkStyle) {
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function getState(string $place, Definition $definition, Marking $markin
{
$workflowMetadata = $definition->getMetadataStore();

$placeEscaped = $this->escape($place);
$placeEscaped = str_replace("\n", ' ', $this->escape($place));

$output = "state $placeEscaped".
(\in_array($place, $definition->getInitialPlaces(), true) ? ' '.self::INITIAL : '').
Expand All @@ -208,7 +208,7 @@ private function getState(string $place, Definition $definition, Marking $markin

$description = $workflowMetadata->getMetadata('description', $place);
if (null !== $description) {
$output .= \PHP_EOL.$placeEscaped.' : '.$description;
$output .= \PHP_EOL.$placeEscaped.' : '.str_replace("\n", ' ', $description);
}

return $output;
Expand All @@ -217,6 +217,7 @@ private function getState(string $place, Definition $definition, Marking $markin
private function getTransitionEscapedWithStyle(MetadataStoreInterface $workflowMetadata, Transition $transition, string $to): string
{
$to = $workflowMetadata->getMetadata('label', $transition) ?? $to;
$to = str_replace("\n", ' ', $to);

$color = $workflowMetadata->getMetadata('color', $transition) ?? null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function testDumpWithoutMarking()
place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle];
place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle];
place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"];
place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition label 3" style="solid" fontcolor="Grey" color="Red"];
place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition
label 3" style="solid" fontcolor="Grey" color="Red"];
place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"];
place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"];
}
Expand All @@ -70,7 +71,8 @@ public function testDumpWithMarking()
place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="c", shape=circle];
place_3c363836cf4e16666669a25da280a1865c2d2874 [label="d", shape=circle];
place_86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="t1" style="solid"];
place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition label 3" style="solid" fontcolor="Grey" color="Red"];
place_3c363836cf4e16666669a25da280a1865c2d2874 -> place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 [label="My custom transition
label 3" style="solid" fontcolor="Grey" color="Red"];
place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_84a516841ba77a5b4648de2cd0dfcb30ea46dbb4 [label="t2" style="solid" color="Blue"];
place_e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98 -> place_3c363836cf4e16666669a25da280a1865c2d2874 [label="t3" style="solid"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ private static function createComplexStateMachineDefinition()
$transitions[] = new Transition('t3', 'b', 'd');

$transitionsMetadata = new \SplObjectStorage();
// PHP 7.2 doesn't allow this heredoc syntax in an array, use a dedicated variable instead
$label = <<<'EOTXT'
My custom transition
label 3
EOTXT;
$transitionsMetadata[$transitionWithMetadataDumpStyle] = [
'label' => 'My custom transition label 3',
'label' => $label,
'color' => 'Grey',
'arrow_color' => 'Red',
];
Expand Down

0 comments on commit 6627291

Please sign in to comment.