Hallo Community,
ich springe gleich mal mit der Tür ins Haus:
Ich versuche seit 2 Tagen eine vernünftige 1:n Relation zwischen den Tabellen "pages" und "tt_content" auf die Reihe zu bekommen. Gemappt wurden die Tabellen erfolgreich, lassen sich getrennt von einander wunderbar "ansprechen". Das Hauptziel ist es aber, die tt_contents im pages-View aufzurufen.
Im Model/Pages.php habe ich den Property contents als
.../ObjectStorage<\vendor\extension\domain\model\Contents> angelegt. Der Property wird dann auch im __construct() als ObjectStorage initialisiert. Nur ist es so, dass die contents im Fluid immer NULL sind. Die Extension wurde mit extension_builder erstellt. Es ist auch suspekt, dass in den Konstruktor nicht "reingesprungen" wird. Das habe ich versucht mit var_dump('text');exit; abzufangen. Im TCA sind die Relationen auch eingetragen (TCA dient ja nur der Backend-Konfiguration, richtig?) (unter 'foreign_table' habe ich sowohl tt_content versucht einzutragen als auch tx_extension_model_... beides ohne Erfolg.)
Die wesentliche Frage ist also:
Besteht überhaupt die Möglichkeit, die Gemappten Models/Tabellen zwischeneinander zu relationalisieren (ohne zusätzliche Tabellen anzulegen)?
Mit Extbase beschäftige ich mich noch nicht allzulange, deswegen hoffe ich dass, ich nur etwas banales vergessen habe.
Vielen Dank für eure Hilfe!
Dateien:
Domain/Model/Pages.php
class Pages extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
...
/**
* contents
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Schimpf\Newsteasersimple\Domain\Model\Contents>
* @cascade remove
*/
protected $contents = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* @return void
*/
protected function initStorageObjects() {
$this->contents = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
...
/**
* Adds a Contents
*
* @param \Schimpf\Newsteasersimple\Domain\Model\Contents $content
* @return void
*/
public function addContent(\Schimpf\Newsteasersimple\Domain\Model\Contents $content) {
$this->contents->attach($content);
}
/**
* Removes a Contents
*
* @param \Schimpf\Newsteasersimple\Domain\Model\Contents $contentToRemove The Contents to be removed
* @return void
*/
public function removeContent(\Schimpf\Newsteasersimple\Domain\Model\Contents $contentToRemove) {
$this->contents->detach($contentToRemove);
}
/**
* Returns the contents
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Schimpf\Newsteasersimple\Domain\Model\Contents> $contents
*/
public function getContents() {
return $this->contents;
}
}
TCA:
...
'contents' => array(
'exclude' => 1,
'label' => 'LLL:EXT:newsteasersimple/Resources/Private/Language/locallang_db.xlf:tx_newsteasersimple_domain_model_pages.contents',
'config' => array(
'type' => 'inline',
//'foreign_table' => 'tx_newsteasersimple_domain_model_contents',
'foreign_table' => 'tt_content',
'foreign_field' => 'pid',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
...
setup.txt:
plugin.tx_newsteasersimple{
persistence {
classes {
Schimpf\Newsteasersimple\Domain\Model\Contents {
mapping {
tableName = tt_content
columns {
pid.mapOnProperty = pid
uid.mapOnProperty = uid
}
}
}
Schimpf\Newsteasersimple\Domain\Model\Pages {
mapping {
tableName = pages
columns {
uid.mapOnProperty = uid
pid.mapOnProperty = pid
title.mapOnProperty = title
sorting.mapOnProperty = sorting
}
}
}
}
}
}