[TYPO3-mvc] extbase: m:n relation between extension table and fe_users

Matthias Nagl t3v4mvc at mnagl.de
Fri Sep 16 23:49:51 CEST 2011


Am Freitag 16 September 2011, 11:50:17 schrieb Franz Koch:
> > I found some information on adding fields and 1:n relations to fe_users
> > and use them in my extbase extension but nothing concerning m:n
> > relations.
> 
> What is your particular problem here? The correct TCA configuration?


In general some kind of howto would be nice. I know the Mittwald and Rau/Kurfürst books but the chapters concerning foreign (t3 internal) tables are only 
covering really simple examples.

In  my special case I managed to get the backend editing of the relations to work with the sql/tca settings appended at the end of this mail. However in spite of 
the TS code also appended I cannot access the additional fields in the template.

- Matthias






# ext_tables.sql #
================================================
# Table structure for table 'fe_users'
CREATE TABLE fe_users (
        tx_sav_lat double default '0' NOT NULL,
        tx_sav_lng double default '0' NOT NULL,
        tx_sav_domain_model_areaofexpertise  int(11) DEFAULT '0' NOT NULL,
);
# Table structure for table 'tx_sav_domain_model_areaofexpertise'
CREATE TABLE tx_sav_domain_model_areaofexpertise (
	uid int(11) NOT NULL auto_increment,
	pid int(11) DEFAULT '0' NOT NULL,


	name varchar(255) DEFAULT '' NOT NULL,

	tstamp int(11) unsigned DEFAULT '0' NOT NULL,
        [...]
	l10n_diffsource mediumblob,

	PRIMARY KEY (uid),
	KEY parent (pid),
	KEY t3ver_oid (t3ver_oid,t3ver_wsid),
	KEY language (l10n_parent,sys_language_uid)
);
# Table structure for table 'tx_sav_areaofexpertise_fe_users_mm'
CREATE TABLE tx_sav_fe_users_areaofexpertise_mm (
	uid_local int(11) unsigned DEFAULT '0' NOT NULL,
	uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
	sorting int(11) unsigned DEFAULT '0' NOT NULL,
	sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,

	KEY uid_local (uid_local),
	KEY uid_foreign (uid_foreign)
);
================================================


# ext_tables.php #
================================================
t3lib_extMgm::addLLrefForTCAdescr('tx_sav_domain_model_areaofexpertise', 
'EXT:sav/Resources/Private/Language/locallang_csh_tx_sav_domain_model_areaofexpertise.xml');
t3lib_extMgm::allowTableOnStandardPages('tx_sav_domain_model_areaofexpertise');
$TCA['tx_sav_domain_model_areaofexpertise'] = array(
	'ctrl' => array(
		'title'	=> 'LLL:EXT:sav/Resources/Private/Language/locallang_db.xml:tx_sav_domain_model_areaofexpertise',
		'label' => 'name',
		'tstamp' => 'tstamp',
		'crdate' => 'crdate',
		'cruser_id' => 'cruser_id',
		'dividers2tabs' => TRUE,
		'versioningWS' => 2,
		'versioning_followPages' => TRUE,
		'origUid' => 't3_origuid',
		'languageField' => 'sys_language_uid',
		'transOrigPointerField' => 'l10n_parent',
		'transOrigDiffSourceField' => 'l10n_diffsource',
		'delete' => 'deleted',
		'enablecolumns' => array(
			'disabled' => 'hidden',
			'starttime' => 'starttime',
			'endtime' => 'endtime',
		),
		'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY) . 'Configuration/TCA/AreaOfExpertise.php',
		'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY) . 'Resources/Public/Icons/tx_sav_domain_model_areaofexpertise.gif'
	),
);

$tempColumns = array (
        'tx_sav_lat' => array (        
                'exclude' => 0,        
                'label' => 'LLL:EXT:sav/Resources/Private/Language/locallang_db.xml:fe_users.tx_sav_lat',        
                'config' => array (
                'type' => 'none',
                )
        ),
        'tx_sav_lng' => array (        
                'exclude' => 0,        
                'label' => 'LLL:EXT:sav/Resources/Private/Language/locallang_db.xml:fe_users.tx_sav_lng',        
                'config' => array (
                'type' => 'none',
                )
        ),
        'tx_sav_domain_model_areaofexpertise' => array (               
                'exclude' => 0,         
                'label' => 'LLL:EXT:sav/Resources/Private/Language/locallang_db.xml:tx_sav_domain_model_areaofexpertise',                
                'config' => array (
                        'type' => 'select',     
                        'foreign_table' => 'tx_sav_domain_model_areaofexpertise',
                        'size' => 5,    
                        'maxitems' => 9999,      
                        "MM" => "tx_sav_fe_users_areaofexpertise_mm",
                )
        ),
);

t3lib_div::loadTCA('fe_users');
t3lib_extMgm::addTCAcolumns('fe_users',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('fe_users','--div--;SAV');
t3lib_extMgm::addToAllTCAtypes('fe_users','tx_sav_domain_model_areaofexpertise;;;;1-1-1');
t3lib_extMgm::addToAllTCAtypes('fe_users','tx_sav_lat;;;;1-1-1', '', 'after:country');
t3lib_extMgm::addToAllTCAtypes('fe_users','tx_sav_lng;;;;1-1-1', '', 'after:country');
================================================


# setup.txt #
================================================
plugin.tx_sav {
	view {
		templateRootPath = {$plugin.tx_sav.view.templateRootPath}
		partialRootPath = {$plugin.tx_sav.view.partialRootPath}
		layoutRootPath = {$plugin.tx_sav.view.layoutRootPath}
	}
	persistence {
		storagePid = {$plugin.tx_sav.persistence.storagePid}
                classes {
                        Tx_Sav_Domain_Model_User {
                                mapping {
                                        tableName = fe_users
                                        # recordType = Tx_Sav_Domain_Model_User
                                }
                        }
                }
	}
}
config.tx_extbase.persistence.classes {
        Tx_Extbase_Domain_Model_FrontendUser {
                subclasses {
                        Tx_Sav_Domain_Model_User = Tx_Sav_Domain_Model_User
                }
        }
        Tx_Sav_Domain_Model_User {
                mapping {
                        tableName = fe_users
                        # recordType = Tx_Sav_Domain_Model_User
                        columns {
                                tx_sav_davprofileurl.mapOnProperty = davProfileUrl
                                tx_sav_lat.mapOnProperty = latitude
                                tx_sav_lng.mapOnProperty = longitude
                                tx_sav_domain_model_specialization.mapOnProperty = specialization
                                tx_sav_domain_model_lawofforeigncountry.mapOnProperty = lawOfForeignCountry
                                tx_sav_domain_model_areaofexpertise.mapOnProperty = areaOfExpertise
                                tx_sav_domain_model_language.mapOnProperty = language
                                tx_sav_domain_model_additionalprofession.mapOnProperty = additionalProfession
                        }
                }
        }
}
================================================


More information about the TYPO3-project-typo3v4mvc mailing list