System: TYPO3 11.5.36 with own expansion to display news and persons. Running on Apache with PHP 7.4.33 and MySQL 5.5.5-10.5.23-MariaDB-0+deb11u1
Setup: We have a person model and a news model.
The news have a property authors and the persons the property news.
Problem: On translated news records the authors will only show up, if we save the news. But when we save the person, the author is only shown in the default language, not in the translated language.
While saving the news record, we have a entry in MM-table for the german and english news with the german ids of the persons. But when we save the person, we have two german news-ids with a german and english person id. It’s flipped around. How to avoid this?
There is no fancy stuff going on in the controller action or in the fluid template. We can’t figure out, how to configurate the property, or how to write a query to address this issue. Are we miss here something?
Details:
In the backend, we create a new news and assign an existing person as author. Then translate the news (the person is already translated). Then we see the authors on the news page in the frontend for the default language (german) and the translated version (english). This is working!
Then when saving the person record without changing any data, the translated record won’t show the author anymore.
Example:
table | language | uid |
---|---|---|
person | 0 (ger) | 1 |
person | 1 (eng) | 2 |
news | 0 (ger) | 10 |
news | 1 (eng) | 11 |
MM-Table looks like this while saving on news:
uid_local (news) | uid_foreign (person) |
---|---|
10 | 1 |
11 | 1 |
MM-Table looks like this while saving on person:
uid_local (news) | uid_foreign (person) |
---|---|
10 | 1 |
10 | 2 |
// TCA from news:
'authors' => array(
'exclude' => 0,
'displayCond' => 'FIELD:sys_language_uid:<=:0',
'l10n_mode' => 'exclude',
'label' => 'LLL:EXT:fgsnews/Resources/Private/Language/locallang_db.xlf:tx_fgsnews_domain_model_news.authors',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_fgspersons_domain_model_person',
'foreign_table_where' => "
AND tx_fgspersons_domain_model_person.sys_language_uid in (-1,0)
AND tx_fgspersons_domain_model_person.hidden = 0
ORDER BY tx_fgspersons_domain_model_person.last_name ASC
",
'MM' => 'tx_fgsnews_news_person_mm',
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 1,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1,
'additionalSearchFields' => 'first_name,last_name',
),
),
),
'behaviour' => [
'allowLanguageSynchronization' => false,
],
),
)
/// TCA from person:
'news' => array(
'displayCond' => 'FIELD:sys_language_uid:<=:0',
'exclude' => 0,
'label' => 'News',
'config' => array(
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_fgsnews_domain_model_news',
'foreign_table_where' => "
AND tx_fgsnews_domain_model_news.sys_language_uid IN (-1,0)
AND tx_fgsnews_domain_model_news.hidden = 0
ORDER BY tx_fgsnews_domain_model_news.starttime Desc
",
'MM' => 'tx_fgsnews_news_person_mm',
'MM_opposite_field' => 'authors',
'autoSizeMax' => 30,
'maxitems' => 999,
'multiple' => 1,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
'l10n_mode' => 'exclude',
'behaviour' => [
'allowLanguageSynchronization' => false,
],
),
)
// News Controller - Action:
public function showAction(News $news) {
$this->view->assign('news', $news);
$authorNames = [];
$authors = $news->getAuthors();
$validAuthors = array();
foreach ($authors as $author) {
$authorNames[] = $author->getFullname();
$personType = $author->getType();
if ($personType != null && $personType->getVisibility() == 2) {
$validAuthors[] = $author;
}
}
$this->view->assign('authors', $validAuthors);
}
// Fluid Template
<f:if condition="{authors}">
<article class="frame frame-mask_text frame-width-85 action-show">
<div class="frame-content">
<div class="bodytext person-contacts">
<f:for each="{authors}" as="person">
<f:render partial="Person/Contact" arguments="{person: person}" />
</f:for>
</div>
</div>
</article>
</f:if>
We tried different settings with l10n_mode and allowLanguageSynchronization, but it ended up in the same results.
If we save the news, everything is working fine. But if we save the person the uid’s in the mm-table get flipped around which causes the problem. We need it to be persistant, so that we can handle and edit the associations bidirectional in both records.
user25189056 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.