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

Add meta tags #49

Merged
merged 1 commit into from
Nov 29, 2023
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
5 changes: 4 additions & 1 deletion Classes/Controller/DateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use WerkraumMedia\Events\Domain\Repository\RegionRepository;
use WerkraumMedia\Events\Events\Controller\DateListVariables;
use WerkraumMedia\Events\Events\Controller\DateSearchVariables;
use WerkraumMedia\Events\Frontend\MetaInformation\DateMetaInformationInterface;
use WerkraumMedia\Events\Pagination\Factory;
use WerkraumMedia\Events\Service\DataProcessingForModels;

Expand All @@ -28,7 +29,8 @@ public function __construct(
private readonly CategoryRepository $categoryRepository,
private readonly Factory $paginationFactory,
private readonly DataProcessingForModels $dataProcessing,
private readonly ExtensionService $extensionService
private readonly ExtensionService $extensionService,
private readonly DateMetaInformationInterface $metaInformationService
) {
}

Expand Down Expand Up @@ -110,6 +112,7 @@ public function showAction(Date $date): ResponseInterface
$this->trigger404('No event found for requested date.');
}

$this->metaInformationService->setDate($date);
$this->view->assign('date', $date);
return $this->htmlResponse();
}
Expand Down
5 changes: 4 additions & 1 deletion Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
use WerkraumMedia\Events\Domain\Model\Dto\EventDemandFactory;
use WerkraumMedia\Events\Domain\Model\Event;
use WerkraumMedia\Events\Domain\Repository\EventRepository;
use WerkraumMedia\Events\Frontend\MetaInformation\EventMetaInformationInterface;
use WerkraumMedia\Events\Service\DataProcessingForModels;

final class EventController extends AbstractController
{
public function __construct(
private readonly EventRepository $eventRepository,
private readonly DataProcessingForModels $dataProcessing,
private readonly EventDemandFactory $demandFactory
private readonly EventDemandFactory $demandFactory,
private readonly EventMetaInformationInterface $metaInformationService
) {
}

Expand All @@ -38,6 +40,7 @@ public function listAction(): ResponseInterface
#[Extbase\IgnoreValidation(['value' => 'event'])]
public function showAction(Event $event): ResponseInterface
{
$this->metaInformationService->setEvent($event);
$this->view->assign('event', $event);
return $this->htmlResponse();
}
Expand Down
10 changes: 8 additions & 2 deletions Classes/Domain/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class Date extends AbstractEntity

protected ?Date $originalDate = null;

protected Event $event;
/**
* Can not be null in theory.
* But editors might disable an event.
* The date might still be available by Extbase, but without event.
* This needs to be handled properly by consuming code for now.
*/
protected ?Event $event;

protected string $canceledLink = '';

Expand Down Expand Up @@ -65,7 +71,7 @@ public function getEndsOnSameDay(): bool
return $end && $this->getStart()->format('Y-m-d') === $end->format('Y-m-d');
}

public function getEvent(): Event
public function getEvent(): ?Event
{
return $this->event;
}
Expand Down
7 changes: 7 additions & 0 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Event extends AbstractEntity
*/
protected ObjectStorage $features;

protected string $keywords;

/**
* @var ObjectStorage<Partner>
*/
Expand Down Expand Up @@ -370,6 +372,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 <coding@daniel-siepmann.de>
*
* 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 WerkraumMedia\Events\Frontend\MetaInformation;

use WerkraumMedia\Events\Domain\Model\Date;

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

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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 WerkraumMedia\Events\Frontend\MetaInformation;

use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
use WerkraumMedia\Events\Domain\Model\Date;

/**
* 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
{
public function __construct(
private readonly MetaTagManagerRegistry $metaTagManagerRegistry
) {
}

public function setDate(Date $date): void
{
$this->setDescription($date);
$this->setKeywords($date);
}

private function setDescription(Date $date): void
{
$description = $date->getEvent()?->getTeaser() ?? '';
if ($description === '') {
return;
}

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

private function setKeywords(Date $date): void
{
$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 <coding@daniel-siepmann.de>
*
* 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 WerkraumMedia\Events\Frontend\MetaInformation;

use WerkraumMedia\Events\Domain\Model\Event;

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

declare(strict_types=1);

/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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 WerkraumMedia\Events\Frontend\MetaInformation;

use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
use WerkraumMedia\Events\Domain\Model\Event;

/**
* 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
{
public function __construct(
private readonly MetaTagManagerRegistry $metaTagManagerRegistry
) {
}

public function setEvent(Event $event): void
{
$this->setDescription($event);
$this->setKeywords($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)
;
}
}
33 changes: 19 additions & 14 deletions Classes/Service/DestinationDataImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,21 @@ public function processData(array $data): int
$this->persistenceManager->persistAll();

// Apply changes via DataHandler (The new way)
$this->logger->info('Apply changes via DataHandler');
if ($event['categories'] ?? false) {
$this->setCategories($event['categories']);
}
if ($event['features']) {
$this->setFeatures($event['features']);
$eventUid = $this->tmpCurrentEvent->getUid();
if (is_int($eventUid) === false) {
throw new Exception('Could not persist and fetch uid of event.', 1701244570);
}

$this->logger->info('Apply changes via DataHandler');
$this->dataHandler->updateEvent(
$eventUid,
[
new Assignment('keywords', implode(', ', $event['keywords'] ?? [])),
$this->getCategories($event['categories'] ?? []),
$this->getFeatures($event['features'] ?? []),
]
);

$this->logger->info('Update slugs');
$this->slugger->update('tx_events_domain_model_event');
$this->slugger->update('tx_events_domain_model_date');
Expand All @@ -202,7 +209,7 @@ public function processData(array $data): int
return 0;
}

private function setCategories(array $categories): void
private function getCategories(array $categories): Assignment
{
$categories = $this->categoriesAssignment->getCategories(new CategoryImport(
$this->import->getCategoryParent(),
Expand All @@ -216,14 +223,13 @@ private function setCategories(array $categories): void
);
$this->eventDispatcher->dispatch($event);

$this->dataHandler->storeAssignments(new Assignment(
$this->tmpCurrentEvent->getUid(),
return Assignment::createFromDomainObjects(
'categories',
$event->getCategories()->toArray()
));
);
}

private function setFeatures(array $features): void
private function getFeatures(array $features): Assignment
{
$features = $this->categoriesAssignment->getCategories(new CategoryImport(
$this->import->getFeaturesParent(),
Expand All @@ -232,11 +238,10 @@ private function setFeatures(array $features): void
true
));

$this->dataHandler->storeAssignments(new Assignment(
$this->tmpCurrentEvent->getUid(),
return Assignment::createFromDomainObjects(
'features',
$features->toArray()
));
);
}

private function setDates(
Expand Down
Loading