Skip to content

Commit

Permalink
[FEATURE] add PageTitleProvider for authors detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaecke committed Feb 2, 2024
1 parent 96260d9 commit 4c56997
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Classes/Controller/NewsAuthorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use GeorgRinger\NumberedPagination\NumberedPagination;
use Mediadreams\MdNewsAuthor\Domain\Repository\NewsAuthorRepository;
use Mediadreams\MdNewsAuthor\Domain\Repository\NewsRepository;
use Mediadreams\MdNewsAuthor\PageTitle\AuthorPageTitleProvider;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
Expand All @@ -55,18 +56,28 @@ class NewsAuthorController extends ActionController
*/
protected $newsRepository;

/**
* titleProvider
*
* @var AuthorPageTitleProvider
*/
protected $titleProvider;

/**
* NewsAuthorController constructor.
*
* @param NewsAuthorRepository $newsAuthorRepository
* @param NewsRepository $newsRepository
* @param AuthorPageTitleProvider $titleProvider
*/
public function __construct(
NewsAuthorRepository $newsAuthorRepository,
NewsRepository $newsRepository
NewsRepository $newsRepository,
AuthorPageTitleProvider $titleProvider
) {
$this->newsAuthorRepository = $newsAuthorRepository;
$this->newsRepository = $newsRepository;
$this->titleProvider = $titleProvider;
}

/**
Expand Down Expand Up @@ -125,11 +136,7 @@ public function listAction($selectedLetter = "", int $currentPage = 1): Response
public function showAction(\Mediadreams\MdNewsAuthor\Domain\Model\NewsAuthor $newsAuthor = null): ResponseInterface
{
if ($newsAuthor != null) {
// write page title
$pageTitle = $newsAuthor->getTitle() . ' ' . $newsAuthor->getFirstname() . ' ' . $newsAuthor->getLastname();
$GLOBALS['TSFE']->page['title'] = $pageTitle;
$GLOBALS['TSFE']->indexedDocTitle = $pageTitle;

$this->titleProvider->setTitle($newsAuthor);
$this->view->assign('newsAuthor', $newsAuthor);

$this->assignPagination(
Expand Down
43 changes: 43 additions & 0 deletions Classes/PageTitle/AuthorPageTitleProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Mediadreams\MdNewsAuthor\PageTitle;

/***************************************************************
*
* Copyright notice
*
* (c) 2016 Christoph Daecke <[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!
***************************************************************/

use TYPO3\CMS\Core\PageTitle\AbstractPageTitleProvider;

/**
* Class AuthorPageTitleProvider
* @package Mediadreams\MdNewsAuthor\PageTitle
*/
final class AuthorPageTitleProvider extends AbstractPageTitleProvider
{
public function setTitle(\Mediadreams\MdNewsAuthor\Domain\Model\NewsAuthor $newsAuthor): void
{
$pageTitle = $newsAuthor->getTitle() . ' ' . $newsAuthor->getFirstname() . ' ' . $newsAuthor->getLastname();
$this->title = $pageTitle;
}
}
10 changes: 10 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ plugin.tx_news {
}

}

# Configure pageTitleProvider
config {
pageTitleProviders {
md_mews_author {
provider = Mediadreams\MdNewsAuthor\PageTitle\AuthorPageTitleProvider
before = record
}
}
}

0 comments on commit 4c56997

Please sign in to comment.