Skip to content

Commit

Permalink
fix: post processing json encoding (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei authored Dec 6, 2022
1 parent 0f91c2a commit 8f3da89
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions EMS/core-bundle/src/Service/Revision/PostProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use EMS\CoreBundle\Form\DataField\JsonMenuNestedEditorFieldType;
use EMS\CoreBundle\Form\DataField\MultiplexedTabContainerFieldType;
use EMS\CoreBundle\Form\Form\RevisionJsonMenuNestedType;
use EMS\Helpers\Standard\Json;
use Psr\Log\LoggerInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormFactoryInterface;
Expand Down Expand Up @@ -137,10 +138,15 @@ public function postProcessing(FormInterface $form, ContentType $contentType, ar
try {
$out = $this->twig->createTemplate($template)->render($context);

if ($fieldType->getDisplayOptions()['json'] && '' !== $out) {
if (!$fieldType->getDisplayOptions()['json']) {
$out = \trim($out);
} elseif (Json::isJson($out)) {
$out = \json_decode($out, true, 512, JSON_THROW_ON_ERROR);
} else {
$out = \trim($out);
if (0 !== \strlen(\trim($out))) {
throw new \RuntimeException(\sprintf('None parsable output in "%s"', $path));
}
$out = null;
}
} catch (\Throwable $e) {
if ($e->getPrevious() && $e->getPrevious() instanceof CantBeFinalizedException) {
Expand Down

0 comments on commit 8f3da89

Please sign in to comment.