Skip to content

Instantly share code, notes, and snippets.

@caseywilliams
Last active March 27, 2017 08:38
Show Gist options
  • Save caseywilliams/8464861 to your computer and use it in GitHub Desktop.
Save caseywilliams/8464861 to your computer and use it in GitHub Desktop.
Extending models and controllers in an extbase TYPO3 extension
<?php
// Table you're modifying
t3lib_div::loadTCA('tx_news_domain_model_news');
// TCA config, arbitrary example: simple text field - nice to include your ext's name in its name so you remember where it's from
$tempColumns = array (
'tx_myext_new_input' => array (
'exclude' => 0,
'label' => 'Some new input field',
'config' => array(
'type' => 'input',
'size' => 10,
'eval' => 'trim'
)
)
)
// More if you want
);
// Add new fields to the TCA
t3lib_extMgm::addTCAcolumns('tx_news_domain_model_news', $tempColumns, 1);
// Optional: tell typo3 where to put the new fields in the BE
// default is to just put them at the end of the 'Extended' tab if you don't include this
t3lib_extMgm::addToAllTCAtypes('tx_news_domain_model_news','tx_myext_domain_model_news');
// Don't forget to update your DB and clear your cache
#
# Add to table structure for the original extension
#
CREATE TABLE tx_news_domain_model_news (
tx_myext_new_input varchar(255) DEFAULT NULL
);
config.tx_extbase {
objects {
# Extending a controller
Tx_News_Controller_NewsController {
className = Tx_Myext_Controller_NewsController
}
# Here's the model
Tx_News_Domain_Model_News {
className = Tx_Myext_Domain_Model_News
}
# Note that if you're trying to extend a repository, you pretty much have to extend the model too,
# even if you don't want to, because the alternative is extending extbase's Repository class and
# changing how it looks for its model. Dumb.
}
# This is the important part for the model. Not necessary when extending a controller.
persistence {
classes {
Tx_Myext_Domain_Model_News {
mapping {
tableName = tx_news_domain_model_news
# If extending the Repository, you may need to get rid of this recordType line
recordType = Tx_News_Domain_Model_News
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment