BlackbitDigitalCommerce / pimcore-data-director

Import Bundle for Pimcore
16 stars 3 forks source link

[NFR] in Export Dataport: allow admin to disable TWIG Lexer validation for field #44

Closed kaurov closed 2 years ago

kaurov commented 2 years ago

If to try to EXPORT existing saved object of any class with MULTY-LANGUAGE field of type WYSIWYG

with HTML content like: <p>{{widget hello="world" }}</p>{{media url="wysiwyg/category/500x500.jpg"}}

using raw field configuration 'fieldName#all' then error happens which I can't process myself because it is in raw fields: [ALERT] Parsing error for field "FieldLAbel#all": Twig\Error\SyntaxError: Unexpected character "&" in "e822858dd47cf5cdb945d5a8d75e9f8b" at line 4. in/vendor/twig/twig/src/Lexer.php:363 Stack trace:

0 /vendor/twig/twig/src/Lexer.php(290): Twig\Lexer->lexExpression()

1 /vendor/twig/twig/src/Lexer.php(184): Twig\Lexer->lexVar()

2 /vendor/blackbit/data-director/lib/Pim/Item/Importer.php(3066): Twig\Lexer->tokenize(Object(Twig\Source))

3 /vendor/blackbit/data-director/lib/Pim/Item/Importer.php(4049): Blackbit\DataDirectorBundle\lib\Pim\Item\Importer->replaceObjectIdentifier('
\n<div clas...', Object(Pimcore\Model\DataObject\MagentoCategory))

4 /vendor/blackbit/data-director/lib/Pim/Parser/PimcoreParser.php(124): Blackbit\DataDirectorBundle\lib\Pim\Item\Importer->getObjectByIdentifier('Pimcore\Model\D...', Object(Pimcore\Model\DataObject\MagentoCategory))

5/vendor/blackbit/data-director/lib/Pim/Parser/PimcoreParser.php(385): Blackbit\DataDirectorBundle\lib\Pim\Parser\PimcoreParser->getValue(Object(Pimcore\Model\DataObject\MagentoCategory), Array)

6 /vendor/blackbit/data-director/lib/Pim/RawData/Importmanager.php(268): Blackbit\DataDirectorBundle\lib\Pim\Parser\PimcoreParser->current()

7 /vendor/blackbit/data-director/Command/ImportCompleteCommand.php(169): Blackbit\DataDirectorBundle\lib\Pim\RawData\Importmanager->importDataport('10', 2, '116167', '62dac9d9cc66e5....', Object(Symfony\Component\HttpFoundation\Request))

8 /vendor/blackbit/data-director/Controller/RestController.php(322): Blackbit\DataDirectorBundle\Command\ImportCompleteCommand::import('10', '', true, true, 'en', NULL, Object(Symfony\Component\HttpFoundation\Request), Array)

9 /vendor/blackbit/data-director/Controller/RestController.php(378): Blackbit\DataDirectorBundle\Controller\RestController->importAction(Object(Symfony\Component\HttpFoundation\Request), '10')

10 /vendor/symfony/http-kernel/HttpKernel.php(152): Blackbit\DataDirectorBundle\Controller\RestController->exportAction(Object(Symfony\Component\HttpFoundation\Request), 'ExportMagentoCa...')

11 /vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)

12 /vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)

13 /public/index.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))

14 {main}

kaurov commented 2 years ago

We found a temporar solution: to extend TWIG tag and delete {{ expressions }}.

Registering a new tag Add a tag by calling the addTokenParser method on the \Twig\Environment instance:

$twig = new \Twig\Environment($loader); $twig->addTokenParser(new Project_Set_TokenParser());

kaurov commented 2 years ago

Pimcore uses {{ expressions }} to replace placeholders with variables values. It is good featere untill somebody will put {{ expression withParam="value" }} like Magento does -- that will cause the TWIG parsing error in Lexer.

kaurov commented 2 years ago

This error happens on both TextArea and WYSIWYG fields in Pimcore.

BlackbitDevs commented 2 years ago

This is fixed in 3.0 and above. Whenever there is an error parsing the value within {{ and }}, the content will be kept without any change.