Skip to content

Instantly share code, notes, and snippets.

@martinhummer
Last active August 29, 2015 14:21
Show Gist options
  • Save martinhummer/360d775d8119dfeb1878 to your computer and use it in GitHub Desktop.
Save martinhummer/360d775d8119dfeb1878 to your computer and use it in GitHub Desktop.
RecordListHook
<?php
namespace Vendor\ExtName\Hooks;
/***************************************************************
*
* Copyright notice
*
* (c) 2015 M. Hummer <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Hook into localRecordList and do additional getTable processing
*/
class RecordListHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface
{
/**
* modifies the DB list query
*
* @param string $table The current database table
* @param integer $pageId The record's page ID
* @param string $additionalWhereClause An additional WHERE clause
* @param string $selectedFieldsList Comma separated list of selected fields
* @param \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList $parentObject Parent localRecordList object
* @return void
*/
public function getDBlistQuery($table, $pageId, &$additionalWhereClause, &$selectedFieldsList, &$parentObject) {
if ($table == 'tx_news_domain_model_news') {
/* @var $beUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
$beUser = $GLOBALS['BE_USER'];
if (!$beUser->isAdmin()) {
$backendUserCategories = $beUser->getCategoryMountPoints();
if ($backendUserCategories === array()) {
return array();
}
else {
$categories = implode(',', $backendUserCategories) ;
$additionalWhereClause .= 'AND tx_news_domain_model_news.uid IN (SELECT sys_category_record_mm.uid_foreign FROM sys_category_record_mm WHERE sys_category_record_mm.uid_local IN (' . $categories . '))' ;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment