Skip to content
Open
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
3 changes: 3 additions & 0 deletions config/routing/1_static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ privacy:
defaults:
_controller: App\Controller\TemplateController::staticAction
templateName: privacy
title: 'Datenschutzerklärung'

impress:
path: /impress
defaults:
_controller: App\Controller\TemplateController::staticAction
templateName: impress
title: 'Impressum'

limits:
path: /grenzwerte
defaults:
_controller: App\Controller\TemplateController::staticAction
templateName: limits
title: 'Übersicht über Schadstoffe und Grenzwerte'

pollutant_pm10:
path: /schadstoffe/feinstaub
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ parameters:
count: 1
path: src/Controller/TemplateController.php

-
message: "#^Ternary operator condition is always true\\.$#"
count: 1
path: src/Controller/TemplateController.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectRepository\\<App\\\\Entity\\\\Station\\>\\:\\:findActiveStations\\(\\)\\.$#"
count: 1
Expand Down
30 changes: 1 addition & 29 deletions src/Controller/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@

use App\Air\SeoPage\SeoPage;
use App\Entity\City;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;

class TemplateController extends AbstractController
{
public function __construct(
protected EntrypointLookupCollectionInterface $entrypointLookupCollection,
ManagerRegistry $managerRegistry
)
{
parent::__construct($managerRegistry);
}

public function cityListAction(): Response
{
return $this->render(
Expand All @@ -30,10 +19,8 @@ public function cityListAction(): Response
);
}

public function staticAction(string $templateName, Breadcrumbs $breadcrumbs, RouterInterface $router, SeoPage $seoPage): Response
public function staticAction(string $templateName, string $title, Breadcrumbs $breadcrumbs, RouterInterface $router, SeoPage $seoPage): Response
{
$title = $this->readH2Tag($templateName);

$templateFilename = sprintf('Static/%s.html.twig', $templateName);

$seoPage->setTitle($title);
Expand All @@ -44,19 +31,4 @@ public function staticAction(string $templateName, Breadcrumbs $breadcrumbs, Rou

return $this->render($templateFilename);
}

protected function readH2Tag(string $templateName): ?string
{
$templateFilename = sprintf('Static/%s.html.twig', $templateName);

$templateContent = $this->renderView($templateFilename);

$crawler = new Crawler($templateContent);
$h2 = $crawler->filter('h2')->first();

/** @see https://github.com/symfony/webpack-encore-bundle/issues/73#issuecomment-514649426 */
$this->entrypointLookupCollection->getEntrypointLookup()->reset();

return $h2 ? $h2->text() : null;
}
}
Loading