Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport pagetitleprovider and seo #60

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Classes/Controller/DateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Wrm\Events\Domain\Repository\RegionRepository;
use Wrm\Events\Events\Controller\DateListVariables;
use Wrm\Events\Events\Controller\DateSearchVariables;
use Wrm\Events\Frontend\MetaInformation\DateMetaInformationInterface;
use Wrm\Events\Pagination\Factory;
use Wrm\Events\Service\DataProcessingForModels;

Expand Down Expand Up @@ -58,6 +59,11 @@ class DateController extends AbstractController
*/
protected $extensionService;

/**
* @var DateMetaInformationInterface
*/
protected $metaInformationService;

public function __construct(
DateDemandFactory $demandFactory,
DateRepository $dateRepository,
Expand All @@ -66,7 +72,8 @@ public function __construct(
Factory $paginationFactory,
DataProcessingForModels $dataProcessing,
EventDispatcher $eventDispatcher,
ExtensionService $extensionService
ExtensionService $extensionService,
DateMetaInformationInterface $metaInformationService
) {
$this->demandFactory = $demandFactory;
$this->dateRepository = $dateRepository;
Expand All @@ -76,6 +83,7 @@ public function __construct(
$this->dataProcessing = $dataProcessing;
$this->eventDispatcher = $eventDispatcher;
$this->extensionService = $extensionService;
$this->metaInformationService = $metaInformationService;
}

protected function initializeAction(): void
Expand Down Expand Up @@ -163,6 +171,7 @@ public function showAction(Date $date): void
$this->trigger404('No event found for requested date.');
}

$this->metaInformationService->setDate($date);
$this->view->assign('date', $date);
}

Expand Down
11 changes: 10 additions & 1 deletion Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Wrm\Events\Controller;

use TYPO3\CMS\Extbase\Annotation as Extbase;
use Wrm\Events\Frontend\MetaInformation\EventMetaInformationInterface;
use Wrm\Events\Domain\Model\Dto\EventDemandFactory;
use Wrm\Events\Domain\Model\Event;
use Wrm\Events\Domain\Repository\EventRepository;
Expand All @@ -25,14 +26,21 @@ class EventController extends AbstractController
*/
protected $demandFactory;

/**
* @var EventMetaInformationInterface
*/
protected $metaInformationService;

public function __construct(
EventRepository $eventRepository,
DataProcessingForModels $dataProcessing,
EventDemandFactory $demandFactory
EventDemandFactory $demandFactory,
EventMetaInformationInterface $metaInformationService
) {
$this->eventRepository = $eventRepository;
$this->dataProcessing = $dataProcessing;
$this->demandFactory = $demandFactory;
$this->metaInformationService = $metaInformationService;
}

protected function initializeAction(): void
Expand All @@ -54,6 +62,7 @@ public function listAction(): void
*/
public function showAction(Event $event): void
{
$this->metaInformationService->setEvent($event);
$this->view->assign('event', $event);
}

Expand Down
10 changes: 10 additions & 0 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class Event extends AbstractEntity
*/
protected $features;

/**
* @var string
*/
protected $keywords = '';

/**
* @var ObjectStorage<Partner>
*/
Expand Down Expand Up @@ -437,6 +442,11 @@ public function getFeatures(): array
return $this->getSortedCategory($this->features);
}

public function getKeywords(): string
{
return $this->keywords;
}

public function setLanguageUid(int $languageUid): void
{
$this->_languageUid = $languageUid;
Expand Down
31 changes: 31 additions & 0 deletions Classes/Frontend/MetaInformation/DateMetaInformationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <[email protected]>
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

namespace Wrm\Events\Frontend\MetaInformation;

use Wrm\Events\Domain\Model\Date;

interface DateMetaInformationInterface
{
public function setDate(Date $date): void;
}
94 changes: 94 additions & 0 deletions Classes/Frontend/MetaInformation/DateMetaInformationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <[email protected]>
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

namespace Wrm\Events\Frontend\MetaInformation;

use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
use Wrm\Events\Domain\Model\Date;
use Wrm\Events\Frontend\PageTitleProvider\DateTitleProviderInterface;

/**
* TYPO3 has many different APIs to set meta information like: Page Title, Meta Tags, OpenGraph Tags, etc.
* Those are combined here for Date detail view.
* That way there is a single place to connect the details to TYPO3 APIs.
*/
final class DateMetaInformationService implements DateMetaInformationInterface
{
/**
* @var MetaTagManagerRegistry
*/
private $metaTagManagerRegistry;

/**
* @var DateTitleProviderInterface
*/
private $titleProvider;

public function __construct(
MetaTagManagerRegistry $metaTagManagerRegistry,
DateTitleProviderInterface $titleProvider
) {
$this->metaTagManagerRegistry = $metaTagManagerRegistry;
$this->titleProvider = $titleProvider;
}

public function setDate(Date $date): void
extcode marked this conversation as resolved.
Show resolved Hide resolved
{
$this->setDescription($date);
$this->setKeywords($date);

$this->titleProvider->setDate($date);
}

private function setDescription(Date $date): void
{
$description = '';
if ($date->getEvent() !== null) {
$description = $date->getEvent()->getTeaser();
}
if ($description === '') {
return;
}
extcode marked this conversation as resolved.
Show resolved Hide resolved

$this->metaTagManagerRegistry
->getManagerForProperty('description')
->addProperty('description', $description)
;
}

private function setKeywords(Date $date): void
{
$keywords = '';
if ($date->getEvent() !== null) {
$keywords = $date->getEvent()->getKeywords();
}
if ($keywords === '') {
return;
}

$this->metaTagManagerRegistry
->getManagerForProperty('keywords')
->addProperty('keywords', $keywords)
;
}
}
31 changes: 31 additions & 0 deletions Classes/Frontend/MetaInformation/EventMetaInformationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <[email protected]>
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

namespace Wrm\Events\Frontend\MetaInformation;

use Wrm\Events\Domain\Model\Event;

interface EventMetaInformationInterface
{
public function setEvent(Event $event): void;
}
88 changes: 88 additions & 0 deletions Classes/Frontend/MetaInformation/EventMetaInformationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <[email protected]>
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/

namespace Wrm\Events\Frontend\MetaInformation;

use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
use Wrm\Events\Domain\Model\Event;
use Wrm\Events\Frontend\PageTitleProvider\EventTitleProviderInterface;

/**
* TYPO3 has many different APIs to set meta information like: Page Title, Meta Tags, OpenGraph Tags, etc.
* Those are combined here for Event detail view.
* That way there is a single place to connect the details to TYPO3 APIs.
*/
final class EventMetaInformationService implements EventMetaInformationInterface
{
/**
* @var MetaTagManagerRegistry
*/
private $metaTagManagerRegistry;

/**
* @var EventTitleProviderInterface
*/
private $titleProvider;

public function __construct(
MetaTagManagerRegistry $metaTagManagerRegistry,
EventTitleProviderInterface $titleProvider
) {
$this->metaTagManagerRegistry = $metaTagManagerRegistry;
$this->titleProvider = $titleProvider;
}

public function setEvent(Event $event): void
extcode marked this conversation as resolved.
Show resolved Hide resolved
{
$this->setDescription($event);
$this->setKeywords($event);

$this->titleProvider->setEvent($event);
}

private function setDescription(Event $event): void
{
$description = $event->getTeaser();
if ($description === '') {
return;
}

$this->metaTagManagerRegistry
->getManagerForProperty('description')
->addProperty('description', $description)
;
}

private function setKeywords(Event $event): void
{
$keywords = $event->getKeywords();
if ($keywords === '') {
return;
}

$this->metaTagManagerRegistry
->getManagerForProperty('keywords')
->addProperty('keywords', $keywords)
;
}
}
Loading
Loading