protected function initialize(array $mapping) {
$this->addCommonColumns();
$columnConfigurations = array();
- foreach ($this->getColumnsDefinitions() as $columnName => $columnDefinition) {
+ foreach ($this->getColumnsDefinition() as $columnName => $columnDefinition) {
$columnConfigurations[$columnName] = $columnDefinition['config'];
$columnConfigurations[$columnName]['mapOnProperty'] = Tx_Extbase_Utility_Extension::convertUnderscoredToLowerCamelCase($columnName);
}
* @param string $tableName An optional table name to fetch the columns definition from
* @return array The TCA columns definition
*/
- public function getColumnsDefinitions($tableName = '') {
+ public function getColumnsDefinition($tableName = '') {
$tableName = strlen($tableName) > 0 ? $tableName : $this->getTableName();
if (TYPO3_MODE === 'FE') {
$GLOBALS['TSFE']->includeTCA();
*/
protected function setRelations(Tx_Extbase_Persistence_Mapper_ColumnMap &$columnMap, $columnConfiguration) {
if (isset($columnConfiguration) && $columnConfiguration['type'] !== 'passthrough') {
- if (isset($columnConfiguration['foreign_table']) && !isset($columnConfiguration['MM']) && !isset($columnConfiguration['foreign_label'])) {
+ if (isset($columnConfiguration['foreign_table']) && !isset($columnConfiguration['MM']) && !(isset($columnConfiguration['foreign_label']) || isset($columnConfiguration['foreign_selector']))) {
if ($columnConfiguration['maxitems'] == 1) {
$this->setOneToOneRelation($columnMap, $columnConfiguration);
} else {
$this->setOneToManyRelation($columnMap, $columnConfiguration);
}
- } elseif (isset($columnConfiguration['foreign_label']) || isset($columnConfiguration['MM'])) {
+ } elseif (isset($columnConfiguration['MM']) || (isset($columnConfiguration['foreign_label']) || isset($columnConfiguration['foreign_selector']))) {
$this->setManyToManyRelation($columnMap, $columnConfiguration);
} else {
$columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_NONE);
// TODO support multi table relationships
$columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
if ($columnConfiguration['type'] === 'inline') {
- $columns = $this->getColumnsDefinitions($columnConfiguration['foreign_table']);
- $columnMap->setChildClassName($this->determineChildClassName($columns[$columnConfiguration['foreign_label']]));
- $columnMap->setChildTableName($columns[$columnConfiguration['foreign_label']]['foreign_table']);
+ $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']);
+ $childKeyFieldName = $this->determineChildKeyFieldName($columnConfiguration);
+ $columnMap->setChildClassName($this->determineChildClassName($columns[$childKeyFieldName]['config']));
+ $columnMap->setChildTableName($columns[$childKeyFieldName]['config']['foreign_table']);
$columnMap->setRelationTableName($columnConfiguration['foreign_table']);
$columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
- $columnMap->setChildKeyFieldName($columnConfiguration['foreign_label']);
+ $columnMap->setChildKeyFieldName($childKeyFieldName);
$columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']);
} else {
$columnMap->setChildClassName($this->determineChildClassName($columnConfiguration));
}
}
+ /**
+ * This method returns the foreign key field name in the relation table. For IRRE setups it will return
+ * the foreign_label; if not present the foreign_selector. Default is uid_foreign.
+ *
+ * @param string $columnConfiguration The column configuration of the parent table relation field
+ * @return string The foreign key field name of the relation table
+ */
+ public function determineChildKeyFieldName($columnConfiguration) {
+ if (isset($columnConfiguration['foreign_label'])) {
+ $childKeyFieldName = $columnConfiguration['foreign_label'];
+ } elseif (isset($columnConfiguration['foreign_selector'])) {
+ $childKeyFieldName = $columnConfiguration['foreign_selector'];
+ } else {
+ $childKeyFieldName = 'uid_foreign';
+ }
+ return $childKeyFieldName;
+ }
+
/**
* This function determines the child class name. It can either be defined as foreign_class in the column configuration (TCA)
* or it must be defined in the extbase framework configuration (reverse mapping from tableName to className).
$leftColumnsDefinition = array(
'rights' => array(
'type' => 'select',
- 'foreign_class' => 'Tx_MyExtension_RightClass',
'foreign_table' => 'tx_myextension_righttable',
'foreign_table_where' => 'WHERE 1=1',
'MM' => 'tx_myextension_mm',
);
$mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
$mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setChildClassName')->with($this->equalTo('Tx_MyExtension_RightClass'));
$mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
$mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
$mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
$rightColumnsDefinition = array(
'lefts' => array(
'type' => 'select',
- 'foreign_class' => 'Tx_MyExtension_LeftClass',
'foreign_table' => 'tx_myextension_lefttable',
'MM' => 'tx_myextension_mm',
'MM_opposite_field' => 'rights'
$leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
$mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
$mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setChildClassName')->with($this->equalTo('Tx_MyExtension_LeftClass'));
$mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
$mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
$mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting_foreign'));
$mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
}
+ /**
+ * @test
+ */
+ public function uid_foreignIsReturnedAsDefaultForChildKeyFieldName() {
+ $leftColumnsDefinition = array(
+ 'rights' => array(
+ 'type' => 'inline',
+ 'foreign_table' => 'tx_myextension_mm',
+ 'foreign_field' => 'uid_local',
+ )
+ );
+ $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
+ $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
+ $this->assertEquals('uid_foreign', $result);
+ }
+
+ /**
+ * @test
+ */
+ public function theChildKeyFieldNameIsReturnedForForeignLabel() {
+ $leftColumnsDefinition = array(
+ 'rights' => array(
+ 'type' => 'inline',
+ 'foreign_table' => 'tx_myextension_mm',
+ 'foreign_field' => 'uid_local',
+ 'foreign_label' => 'the_child_key_field_name',
+ )
+ );
+ $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
+ $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
+ $this->assertEquals('the_child_key_field_name', $result);
+ }
+
+ /**
+ * @test
+ */
+ public function theChildKeyFieldNameIsReturnedForForeignSelector() {
+ $leftColumnsDefinition = array(
+ 'rights' => array(
+ 'type' => 'inline',
+ 'foreign_table' => 'tx_myextension_mm',
+ 'foreign_field' => 'uid_local',
+ 'foreign_selector' => 'the_child_key_field_name',
+ )
+ );
+ $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
+ $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
+ $this->assertEquals('the_child_key_field_name', $result);
+ }
+
/**
* @test
*/
);
$relationTableColumnsDefiniton = array(
'uid_local' => array(
- 'foreign_class' => 'Tx_MyExtension_LocalClass',
- 'foreign_table' => 'tx_myextension_localtable'
+ 'config' => array('foreign_table' => 'tx_myextension_localtable')
),
'uid_foreign' => array(
- 'foreign_class' => 'Tx_MyExtension_RightClass',
- 'foreign_table' => 'tx_myextension_righttable'
+ 'config' => array('foreign_table' => 'tx_myextension_righttable')
)
);
$rightColumnsDefinition = array(
);
$mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
$mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
- $mockColumnMap->expects($this->once())->method('setChildClassName')->with($this->equalTo('Tx_MyExtension_RightClass'));
$mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
$mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
$mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
$mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition', 'determineChildClassName'), array(), '', FALSE);
$mockDataMap->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
- $mockDataMap->expects($this->once())->method('determineChildClassName')->with($this->equalTo($relationTableColumnsDefiniton['uid_foreign']))->will($this->returnValue('Tx_MyExtension_RightClass'));
$mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
}