<?php namespace SGalinski\SgNews\TCA; /*************************************************************** * Copyright notice * * (c) sgalinski Internet Services (https://www.sgalinski.de) * 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 2 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! ***************************************************************/ use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; /** * This class contains methods for usage within the TCA forms. */ class TcaProvider implements SingletonInterface { /** * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface */ protected $objectManager; /** * Constructor * * @throws \InvalidArgumentException */ public function __construct() { $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); } /** * Hook method for calculating the title for articles and copying the subtitle into the nav_title field * * @param DataHandler $tceMain * @return void */ public function processDatamap_afterAllOperations(DataHandler $tceMain) { /** @var array $tablesData */ foreach ($tceMain->datamap as $table => $tablesData) { if ($table !== 'pages') { continue; } /** @var string $identity */ foreach ($tablesData as $identity => $tableData) { if (strpos($identity, 'NEW') !== FALSE) { $identity = $tceMain->substNEWwithIDs[$identity]; } $translationRow = []; $pagesIdentity = (int) $identity; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $queryBuilder->getRestrictions()->removeAll(); $row = $queryBuilder->select('doktype', 'subtitle', 'lastUpdated', 'tx_sgnews_highlighted', 't3ver_oid') ->from('pages') ->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($pagesIdentity, \PDO::PARAM_INT)) ) ->execute()->fetch(); $workspaceOriginalId = (int) $row['t3ver_oid']; if ($workspaceOriginalId > 0) { $row = $queryBuilder->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($workspaceOriginalId, \PDO::PARAM_INT)) )->execute()->fetch(); } // only articles $row['doktype'] = (int) $row['doktype']; if (!is_array($row) || !count($row) || (int) $row['doktype'] !== 116) { continue; } $prefix = ''; if ($row['tx_sgnews_highlighted'] >= 1) { $prefix = 'Top - '; } $subtitle = $row['subtitle']; $calculatedTitle = $prefix . strftime('%Y-%m-%d', $row['lastUpdated']) . ' - ' . $subtitle; $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table); $queryBuilder->update($table) ->where( $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($identity, \PDO::PARAM_INT)) ) ->set('nav_title', $subtitle, TRUE) ->set('title', trim($calculatedTitle), TRUE) ->execute(); } } } }