Friday 2 January 2015

tt_news: Modify query to database

tt_news is an extension of TYPO3 designed to publish news in our website. It's a very popular extension and it allows publish and manage news about our company, association, etc. You can find extension manual here.

Suppose that we have our own extension with our own plugins and we want to indicate that in the news list we only want news with ID greater than 100... So we should use a hook that is prepared for the extension in order to modify the database query.

In this example we used TYPO3 4.4.4 and tt_news 3.0.1. Files to modify are:
ext_localconf.php

if (TYPO3_MODE == 'FE')  { require_once(t3lib_extMgm::extPath('user_t3_test').'user_t3_test_selectHook.php'); }
$TYPO3_CONF_VARS['EXTCONF']['tt_news']['selectConfHook'][] = 'user_t3_test_selectHook';


user_t3_test_selectHook.php

class user_t3_test_selectHook {
public function processSelectConfHook(&$parentObject, $selectConf) {
$selectConf['where'] .= ' AND uid > 100 ';
return $selectConf;
}


I hope you find it useful! Regards!

No comments:

Post a Comment