<?php namespace SGalinski\SgNews\Hooks; /*************************************************************** * 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 SGalinski\SgNews\Service\LicensingService; use SGalinski\SgNews\Utility\BackendNewsUtility; use TYPO3\CMS\Backend\Controller\PageLayoutController as CorePageLayoutController; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** * Backend edid form hook */ class PageLayoutController { /** * Sets the default value for the pages author field * to the name of the logged-in user * * @param array $parameters * @param CorePageLayoutController $controller * @return string * @throws \InvalidArgumentException */ public function addNewsModuleLink(array $parameters = [], $controller): string { $out = ''; if (!(int) $controller->id || !LicensingService::checkKey()) { return $out; } $pageRow = BackendUtility::getRecord('pages', $controller->id); $acceptedDoktypes = [BackendNewsUtility::NEWS_DOKTYPE, BackendNewsUtility::CATEGORY_DOKTYPE]; if ( !is_array($pageRow) || !count($pageRow) || !in_array((int) $pageRow['doktype'], $acceptedDoktypes, TRUE) ) { return $out; } $categoryRow = (int) $pageRow['doktype'] === BackendNewsUtility::CATEGORY_DOKTYPE ? $pageRow : BackendUtility::getRecord('pages', (int) $pageRow['pid']); if ( !is_array($categoryRow) || !count($categoryRow) || (int) $categoryRow['doktype'] !== BackendNewsUtility::CATEGORY_DOKTYPE ) { return $out; } $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); $pageRenderer->loadRequireJsModule('TYPO3/CMS/SgNews/Backend'); /** @var IconFactory $iconFactory */ $iconFactory = GeneralUtility::makeInstance(IconFactory::class); $icon = $iconFactory->getIcon('sg_news-module-transparent'); $icon = '<span style="vertical-align: middle; display:inline-block;">' . $icon . '</span>'; $buttonLabel = LocalizationUtility::translate('backend.button.goToNewsModule', 'SgNews'); $buttonLabel = '<span style="vertical-align: middle;">' . $buttonLabel . '</span>'; $path = ''; $onclick = 'TYPO3.SgNewsModule.sgNewsGoToNewsModule(' . $categoryRow['uid'] . $path . '); return false;'; $wrap = ' <div class="btn-group" role="group">%s</div>'; $link = '<a href="#" onclick="' . $onclick . '" class="btn btn-primary">%s</a>'; $link = sprintf($link, $icon . ' ' . $buttonLabel); $out = sprintf($wrap, $link); return $out; } }