feat: refine flipbook start modes and UI behavior

This commit is contained in:
Juergen
2026-04-13 21:34:29 +02:00
commit 9f9b1c9935
23 changed files with 1007 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Mummert\FlipbookBundle\Contao\Manager;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Mummert\FlipbookBundle\FlipbookBundle;
class Plugin implements BundlePluginInterface
{
public function getBundles(ParserInterface $parser): iterable
{
return [
BundleConfig::create(FlipbookBundle::class)
->setLoadAfter([ContaoCoreBundle::class]),
];
}
}
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace Mummert\FlipbookBundle\Controller\ContentElement;
use Contao\ContentModel;
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement;
use Contao\CoreBundle\Twig\FragmentTemplate;
use Contao\FilesModel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
#[AsContentElement(type: 'blatterbares_pdf', category: 'media', template: 'content_element/blatterbares_pdf')]
class BlatterbaresPdfController extends AbstractContentElementController
{
protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response
{
$template->set('pdfUrl', $this->resolvePdfUrl($model));
$template->set('showNavigation', '1' === (string) ($model->flipbookShowNavigation ?? '1'));
$template->set('initialRenderPages', $this->normalizeInitialRenderPages((string) ($model->flipbookInitialPages ?? '4')));
$template->set('startMode', $this->normalizeStartMode((string) ($model->flipbookStartMode ?? 'center')));
return $template->getResponse();
}
private function resolvePdfUrl(ContentModel $model): string
{
$uuid = (string) ($model->flipbookPdfSrc ?? '');
if ('' === $uuid) {
return '';
}
$fileModel = FilesModel::findByUuid($uuid);
if (null === $fileModel) {
return '';
}
$path = trim((string) $fileModel->path, '/');
if ('' === $path || !str_ends_with(strtolower($path), '.pdf')) {
return '';
}
return '/'.implode('/', array_map('rawurlencode', explode('/', $path)));
}
private function normalizeInitialRenderPages(string $value): int
{
$count = (int) $value;
if ($count < 2) {
return 2;
}
if ($count > 4) {
return 4;
}
return $count;
}
private function normalizeStartMode(string $value): string
{
if ('spread' === $value || 'cover' === $value) {
return 'spread';
}
return 'center';
}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Mummert\FlipbookBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class FlipbookExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.yaml');
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Mummert\FlipbookBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class FlipbookBundle extends Bundle
{
public function getPath(): string
{
return dirname(__DIR__);
}
}