Edit the translation of a dynamic content

My Mautic version is:: 4.4.8
My PHP version is: 8.1.6

My problem is:
I have created a Dynamic content, and set it as a translation for another one.
when I try to edit the translation, it keeps give me an error, and I cant edit it or clone it ether any way.

These errors are showing in the log:
Uncaught PHP Exception Doctrine\DBAL\Exception: "An exception occurred while executing 'SELECT d0_.id AS id_0, d0_.name AS name_1, d0_.lang AS lang_2 FROM dynamic_content … etc.

I tested it with 4.4.7 and PHP 8.0 … no issues. PHP 8.1 is not supported yet. Give it a try with PHP 8.0 maybe. If I find the time, I will update my instance today and test 4.4.8 and PHP 8.0.

image

It’s still an issue. You can see the dynamic content list, but you can not edit or view the translation variants.
Mautic version is:: 4.5 (but I checked the code of 4.4.11 too and I can’t see any changes in the Dynamic content bundle)
PHP version is: 8.0.27-fpm

I found what the problem is, but I don’t know why it happens and how I can solve.
The problem: The DynamicContentModel’s getLookupResults function’s $filter parameter is array like this:
array(5) {
[“type”]=> string(14) “dynamicContent”
[“filter”]=> array(38) {
[“initializer”]=> int(1)
[“cloner”]=> int(1)
[“isInitialized”]=> int(0)

and that`s why the called getDynamicContentList function of the DynamicContentRepository gives an error 500, because this fails:

if (is_array($search)) {
$search = array_map(‘intval’, $search);
$q->andWhere($q->expr()->in(‘e.id’, ‘:search’))
->setParameter(‘search’, $search);
(Exception Doctrine\DBAL\Exception
"An exception occurred while executing
‘SELECT d0_.id AS id_0, d0_.name AS name_1, d0_.lang AS lang_2
FROM dynamic_content d0_
WHERE d0_.id IN (?)
AND d0_.translation_parent_id IS NULL
AND d0_.id NOT IN (?)
ORDER BY d0_.name ASC’
with params [{“initializer”:1,
cloner”:1,
isInitialized”:0,
“\u0000Mautic\DynamicContentBundle\Entity\DynamicContent\u0000id”:16,
“\u0000Mautic\DynamicContentBundle\Entity\DynamicContent\u0000name”:0,


)

The same flow works when it’s about the emails and I can’t see any differences.
Any idea how to solve this? Thanks in advance! :slight_smile:

Can anyone confirm that this feature works under version 5? (Viewing and editing a language version of a dynamic content)
Is it worth to upgrade?

I found the reason of the problem and I have a possible solution for it.

So the problem again:
When you have a dynamic content with language variants, you can see the dynamic content list (parent, language variants), but you can not edit the translation variants.

The reason of the problem:

In the EntityLookupChoiceLoader (\app\bundles\CoreBundle\Form\ChoiceLoader\EntityLookupChoiceLoader.php) class the getChoices method needs the $data, but that is always null.
So the method grabs the $this->selected

if (null === $data) {
    $data = $this->selected;
}

That comes from the onFormPostSetData method of the class

public function onFormPostSetData(FormEvent $event)
{
    $this->selected = (array) $event->getData();
}

While debugging I can see when an Email entity has a language variant (Mautic\EmailBundle\Entity\Email) the $event->getData() is always an integer - the ID of the parent of the selecte language variant.
But when its a dynamic content entity (Mautic\DynamicContentBundle\Entity\DynamicContent) the $event->getData() is an object. Thats why we have a problem and that`s because of some Doctrine lazy load issue.

My solution is a fix in the onFormPostSetData method.

public function onFormPostSetData(FormEvent $event)
{
    if (is_object($event->getData()) && $event->getData() instanceof \Doctrine\ORM\Proxy\Proxy) {
        $event->getData()->__load();

        $event->setData($event->getData()->getId());
    }

    $this->selected = (array) $event->getData();
}

If anyone has a better solution, let me know please! :slight_smile:

I tested the Mautic versions from 4.4.5 till 4.4.12 - every of them has the same problem, but I don`t know anything about the Mautic 5 versions.