Skip to content

Commit

Permalink
Merge pull request #315 from wsexport/prefill-title-underscores
Browse files Browse the repository at this point in the history
Normalize the ?title= parameter
  • Loading branch information
MusikAnimal committed Jan 18, 2021
2 parents bacc93b + b436605 commit 2f2879a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ public function home(
return $this->export( $request, $api, $fontProvider, $generatorSelector );
}

$title = $request->get( 'title' );
$font = $this->getFont( $request, $api->getLang(), $fontProvider );
$images = (bool)$request->get( 'images', true );
return $this->render( 'export.html.twig', [
'fonts' => $fontProvider->getAll(),
'font' => $font,
'formats' => GeneratorSelector::$formats,
'format' => $this->getFormat( $request ),
'title' => $title,
'title' => $this->getTitle( $request ),
'lang' => $api->getLang(),
'images' => $images,
'nocache' => $nocache,
Expand Down Expand Up @@ -198,6 +197,15 @@ private function getFormat( Request $request ): string {
return $format;
}

/**
* Get the page title from either the 'title' or 'page' parameters of the request.
*/
private function getTitle( Request $request ): string {
// It doesn't always make sense to fall back to the 'page' parameter, because that's what prompts the export,
// but for error pages it's useful.
return ucfirst( str_replace( '_', ' ', $request->get( 'title', $request->get( 'page' ) ) ) );
}

/**
* Error page handler, to always show the export form with any HTTP error message.
*
Expand All @@ -222,7 +230,7 @@ public function error( Request $request, Throwable $exception, Api $api, FontPro
'font' => $request->get( 'fonts' ),
'formats' => GeneratorSelector::$formats,
'format' => $this->getFormat( $request ),
'title' => $request->get( 'title', $request->get( 'page' ) ),
'title' => $this->getTitle( $request ),
'lang' => $api->getLang(),
'images' => true,
'messages' => [
Expand Down

0 comments on commit 2f2879a

Please sign in to comment.