Bug #78026

get translation of extbase object / persistenceSession does not track languages

Added by Ruud Silvrants almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Localization
Target version:
-
Start date:
2016-09-21
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

When getting a translation of an existing extbase object the original object is returned.
The usecase is to show the translated record together with the original record on a page.

The problem is that the persistenceSession registers an object based on uid and classname, but the language is not respected in this session. Therefore when the datamapper is invoking the method 'hasIdentifier' on this class (typo3/sysext/extbase/Classes/Persistence/Generic/Session.php) this returns true and the original object is retrieved from the persistenceSession.

A workaround for this is to inject the persistenceSession in the repository and unregister the object in the persistenceSession:

/** * persistenceSession * * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session * @inject
*/
protected $persistenceSession = null;

/**
  • @param Item $item
  • @param int $languageUid
  • @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
    */
    public function findTranslationOfItem($item, $languageUid) {
    $query = $this->createQuery();
    $querySettings = $query->getQuerySettings();
    $querySettings->setLanguageUid($languageUid);
    $query->setQuerySettings($querySettings);
    $query->matching($query->equals('uid', $item->getUid()));
    //Unregister the orignal object else the orignal will be returned
    $this->persistenceSession->unregisterObject($item);
return $query->execute()->getFirst();
}

Related issues

Is duplicate of TYPO3 Core - Bug #59992: Persistence session doesn't take overlays into accountAccepted2014-06-30

Actions

Also available in: Atom PDF