Altering behavior of existing extensions in Typo3 through the TCA
Monday, December 18th, 2006I’ve learnt some really nice things the last days with Typo3. I got familiar with the TCA. The TCA [1] controls behavior and data for tables in Typo3. I needed to change the Country field in tt_address from being a boring string input field to become a dropdown selection field. I’m amazed over how simple this is to accomplish.
I got a custom extension mostly generated using the extension kickstarter [2]. That extension adds a lot of extra tables and record types for my client. Amongs these a list of countries and regions for each countries. I wanted to connect these countries to a tt_address record and by that replace the standard country string input field.
This is done easily by editing my ext_tables.php and add the following piece of code:
-
-
//
-
// modify tt_address country field to be a dropdown..
-
//
-
"exclude" => 1,
-
"label" => "LLL:EXT:lang/locallang_general.xml:LGL.country", //we’ll borrow the original title for country fields
-
"type" => "select",
-
),
-
"foreign_table" => "tx_mereaclientname_countries",
-
"foreign_table_where" => "ORDER BY tx_mereaclientname_countries.uid",
-
"size" => 1,
-
"minitems" => 0,
-
"maxitems" => 1,
-
)
-
),
-
);
-
-
t3lib_div::loadTCA("tt_address");
-
t3lib_extMgm::addTCAcolumns("tt_address",$ttAddressModCols,1);
-
That’s it
What it does is; create a temporary array of settings for the tt_address table called ttAddressModCols and define a new definition of the country field for tt_address (replacing the current) with my database relation field. It uses the standard country label translation for consistancy. Finaly load tt_address’ TCA definition and merge it with our adaptation.
[update 2006-12-18]
Noteworthy when doing like above is that data is stored in the original database field. You might want to replace that field as well with your own type. For the above I would go with
alter table tt_address change country country INTEGER
in the sql script of my extension. Feels a bit wrong to use varchar to store integers…
REFERENCES:
[1]http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.0.0/view/4/1/
[2] http://typo3.org/extensions/repository/view/kickstarter/0.3.8/