Last active
December 16, 2016 16:08
-
-
Save InvisibleKind/8185705 to your computer and use it in GitHub Desktop.
ExtBase localization of child records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Product\Hooks; | |
use TYPO3\CMS\Core\DataHandling\DataHandler; | |
use TYPO3\CMS\Core\Database\DatabaseConnection; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
class DataHandlerHooks { | |
/** | |
* @var DatabaseConnection | |
*/ | |
private $dbh; | |
public function __construct() { | |
$this->dbh = $GLOBALS['TYPO3_DB']; | |
} | |
public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, DataHandler &$dh) { | |
//$a = 1; | |
if ($status == 'new') { | |
$realId = $dh->substNEWwithIDs[$id]; | |
// $incomingTable = $dh->substNEWwithIDs_table[$id]; | |
foreach ($dh->remapStack as $remapStackItem) { | |
if ($remapStackItem['args'][$remapStackItem['pos']['tcaFieldConf']]['foreign_table'] == $table && | |
$remapStackItem['args'][$remapStackItem['pos']['tcaFieldConf']]['type'] == 'inline' | |
) { | |
$languageUid = $this->dbh->exec_SELECTgetSingleRow( | |
'sys_language_uid', | |
$remapStackItem['args'][$remapStackItem['pos']['table']], | |
'uid=' . intval($remapStackItem['args'][$remapStackItem['pos']['id']]) | |
)['sys_language_uid']; | |
$this->dbh->exec_UPDATEquery($table, 'uid=' . intval($realId), ['sys_language_uid' => $languageUid]); | |
$fieldArray['sys_language_uid'] = $languageUid; | |
$dh->checkValue_currentRecord['sys_language_uid'] = $languageUid; | |
} | |
} | |
} | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (TYPO3_MODE === 'BE') { | |
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = | |
'EXT:product/Classes/Hooks/DataHandlerHooks.php:&Vendor\Product\Hooks\DataHandlerHooks'; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Product\Domain\Model; | |
class Parent extends AbstractEntity { | |
// | |
// class attributes go here... | |
// | |
/** | |
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Product\Domain\Model\Child> | |
* @lazy | |
*/ | |
protected $children; | |
/** | |
* @var \Vendor\Product\Domain\Repository\ChildRepository | |
* @inject | |
*/ | |
protected $_childRepository; | |
// | |
// class methods go here... | |
// | |
/** | |
* @return int | |
*/ | |
public function getLocalizedUid() { | |
return $this->_localizedUid; | |
} | |
public function getChildren() { | |
// TODO: check inconsistence here, since $children will not equal $this->children | |
// also $this->children = $children; is incorrect, becasue $this->children are of type ObjectStorage, | |
// but $children - QueryResultInterface | |
$children = $this->_childRepository->findByParentUid($this->getLocalizedUid()); | |
return $children; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment