Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParentChildViewListener error within element groups in news articles #245

Closed
CMSworker opened this issue Mar 25, 2024 · 5 comments
Closed

Comments

@CMSworker
Copy link
Contributor

CMSworker commented Mar 25, 2024

While trying to use the new "element group" element in a news article, I stumbled across an error that is probably related to the pid check of changelanguage.

Steps to reproduce:

  • Contao 5.3.3 with NewsBundle and ChangeLanguage 3.6.5 installed
  • Add a news archive
  • Add a new news article
  • Add a Element Group element (that was introduced with Contao 5.3)
  • Try to edit the children of the Element Group brings up the error "Field tl_content.pid does not seem to be related"

Stack trace:

Exception:
Field tl_content.pid does not seem to be related

  at [...]\vendor\contao\core-bundle\contao\library\Contao\Model.php:685
  at Contao\Model->getRelated('pid')
     ([...]\vendor\terminal42\contao-changelanguage\src\EventListener\BackendView\ParentChildViewListener.php:55)
  at Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener->getCurrentPage()
     ([...]\vendor\terminal42\contao-changelanguage\src\EventListener\BackendView\AbstractViewListener.php:63)
  at Terminal42\ChangeLanguage\EventListener\BackendView\AbstractViewListener->onLoad(object(DC_Table))
     ([...]\vendor\terminal42\contao-changelanguage\src\EventListener\BackendView\AbstractViewListener.php:35)
  at Terminal42\ChangeLanguage\EventListener\BackendView\AbstractViewListener->Terminal42\ChangeLanguage\EventListener\BackendView\{closure}(object(DC_Table))
     ([...]\vendor\contao\core-bundle\contao\drivers\DC_Table.php:227)
  at Contao\DC_Table->__construct('tl_content', array('tables' => array('tl_news_archive', 'tl_news', 'tl_content'), 'table' => array('Contao\\CoreBundle\\Controller\\BackendCsvImportController', 'importTableWizardAction'), 'list' => array('Contao\\CoreBundle\\Controller\\BackendCsvImportController', 'importListWizardAction')))
     ([...]\vendor\contao\core-bundle\contao\classes\Backend.php:291)
  at Contao\Backend->getBackendModule('news', null)
     ([...]\vendor\contao\core-bundle\contao\controllers\BackendMain.php:144)
  at Contao\BackendMain->run()
     ([...]\vendor\contao\core-bundle\src\Controller\BackendController.php:44)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     ([...]\vendor\symfony\http-kernel\HttpKernel.php:181)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     ([...]\vendor\symfony\http-kernel\HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     ([...]\vendor\symfony\http-kernel\Kernel.php:197)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     ([...]\web\index.php:42)

// Edit 1: The error is about tl_content.pid - that has the ID of the news article where I added the content element, so the relation of the element group to the news article seems to be correct

// Edit 2: Made tests with a new, fresh installation:
Test 1: Just one archive, no second language: Children of element group cannot be edited (same error as above)
Test 2: Added second archive, no second language: same error as above
Test 3: Added second language and third archive, linked to first archiv of first language: same error
Test 4: Added a fourth archive, linked to second archiv of first language: same error
So it doesn't seem to be related to the numbers of archives or installed languages.
Test 5: Deinstalled the changelanguage extension: No error, all element goup children within the news articles in all archives are editable again.

@CMSworker CMSworker changed the title ParentChildViewListener error within element groups in second news archive ParentChildViewListener error within element groups in news articles Mar 25, 2024
@aschempp
Copy link
Member

Fixed in eb1183d

@CMSworker
Copy link
Contributor Author

Thank you @aschempp

Just testet it... unfortunaltely, now I get another error that is maybe be caused by your recent changes:

  • Test with a "fresh" Contao installation and changelanguage 3.7.1 installed
  • Added a news archive in englisch "Hauptarchiv"
  • Added a second news archiv in german and there selected the english one as the referred "Hauptarchiv"
  • Now add a news article in the english archive
  • Then add a news article in the german archive and select the english article as reference
  • When you now click "Save and close" OR go back to the news overview and try to open the articles of the german (second) news archive, the following error occurs:
in [...]\vendor\terminal42\contao-changelanguage\src\EventListener\DataContainer\MissingLanguageIconListener.php (line 297)

                            LEFT JOIN $ptable pt ON p.$parentField=pt.id
                        WHERE pt.id > 0
                    SQL,
            );
            return $this->translationCache[$table][$id] ?? null;
        }
    }
TypeError:
Terminal42\ChangeLanguage\EventListener\DataContainer\MissingLanguageIconListener::getChildTranslation(): Return value must be of type ?int, string returned

  at [...]\vendor\terminal42\contao-changelanguage\src\EventListener\DataContainer\MissingLanguageIconListener.php:297
  at Terminal42\ChangeLanguage\EventListener\DataContainer\MissingLanguageIconListener->getChildTranslation(2, 'tl_news', 'tl_news_archive', 'master')

I have to make more tests (maybe I have a configuration issue in my test setup) but wanted to let you know already...

@fritzmg
Copy link
Sponsor Contributor

fritzmg commented May 23, 2024

The issue is that integer values are only returned as integers from the database under PDO in PHP 8 and higher. Otherwise they will be returned as strings.

@CMSworker
Copy link
Contributor Author

Quick test: Yes, adding (int) in line 297 of

[...]/vendor/terminal42/contao-changelanguage/src/EventListener/DataContainer/MissingLanguageIconListener.php
return (int)$this->translationCache[$table][$id] ?? null;

seems to solve the problem for the news.

(Didn't test other such SQL returns in the code)

@fritzmg
Copy link
Sponsor Contributor

fritzmg commented May 23, 2024

#250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants