Skip to content

Commit 9eca4d4

Browse files
committed
refactor: improve headline processing and HTML tag handling in Str, ensure better type consistency and enhance filters and projector logic across components
1 parent c2cb570 commit 9eca4d4

18 files changed

Lines changed: 133 additions & 53 deletions

contao/templates/content_element/flare_listview.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<br><small>{{ 'list.default_template.description'|trans({}, 'flare') }}</small>
3131
</div>
3232

33-
{% if app.request.get('_preview') or app.debug %}
33+
{% if app.debug %}
3434
{% for entry in flare_list.entries %}
3535
<details>
3636
<summary>#{{ entry.id }} <a href="{{ flare_list.to(entry.id) }}">{{ (entry.title ?? entry.email ?? entry.alias ?? null) ?: ('to reader <' ~ loop.index ~ '>') }}</a></summary>

contao/templates/content_element/flare_reader.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<br><small>{{ 'reader.default_template.description'|trans({}, 'flare') }}</small>
1515
</div>
1616

17-
{% if app.request.get('_preview') or app.debug %}
17+
{% if app.debug %}
1818
<dl style="display: grid; grid-template-columns: max-content auto; gap: .125rem 1rem; font-family: monospace; padding: 1rem; background: #def; font-size: .9em; height: fit-content; max-height: 80svh; min-height: min(500px, 100%); overflow-y: auto;">
1919
<strong style="grid-column: 1 / -1; margin-bottom: 1rem">{{ model.table }}</strong>
2020
{% for key, field in model.row -%}

src/Controller/ContentElement/ListViewController.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,12 @@ protected function getBackendResponse(Template $template, ContentModel $model, R
161161
return new Response($e->getMessage());
162162
}
163163

164-
if (($headline = StringUtil::deserialize($model->headline, true)) && isset($headline['value'])) {
165-
$unit = ($headline['unit'] ?? null) ?: 'h2';
166-
$hl = \sprintf('<%s>%s</%s>', $unit, $headline['value'], $unit);
167-
}
168-
169164
return new Response(\sprintf(
170-
'%s%s <span class="tl_gray">[%s, %s]</span>',
171-
$hl ?? '',
172-
$listModel->title,
173-
$this->translator->trans($listModel->type, [], 'flare_list'),
174-
$listModel->dc
165+
'<div>%s</div><span>%s</span> <span class="tl_gray">[%s, %s]</span>',
166+
(string) Str::formatHeadline($model->headline),
167+
\strip_tags((string) $listModel->title),
168+
\strip_tags($this->translator->trans($listModel->type, [], 'flare_list')),
169+
\strip_tags((string) $listModel->dc)
175170
));
176171
}
177172
}

src/DataContainer/ListContainer.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
namespace HeimrichHannot\FlareBundle\DataContainer;
66

7+
use Contao\Controller;
78
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
89
use Contao\DataContainer;
910
use Doctrine\DBAL\Connection;
1011
use HeimrichHannot\FlareBundle\Contract\ListDriver\OnSubmitDcContract;
12+
use HeimrichHannot\FlareBundle\Model\FilterModel;
13+
use HeimrichHannot\FlareBundle\Model\ListModel;
1114
use HeimrichHannot\FlareBundle\Query\TableAliasRegistry;
1215
use HeimrichHannot\FlareBundle\Registry\ListDriverRegistry;
1316
use HeimrichHannot\FlareBundle\Util\DcaHelper;
@@ -22,6 +25,25 @@ public function __construct(
2225
private readonly ListDriverRegistry $listDriverRegistry,
2326
) {}
2427

28+
public function hasFilterConfigured(ListModel $listModel, string $filterType): bool
29+
{
30+
$filterTable = FilterModel::getTable();
31+
32+
$result = $this->connection->createQueryBuilder()
33+
->select('1')
34+
->from($filterTable)
35+
->where('pid = :pid')
36+
->andWhere('published = 1')
37+
->andWhere('tstamp > 0')
38+
->andWhere('type = :type')
39+
->setMaxResults(1)
40+
->setParameter('pid', $listModel->id)
41+
->setParameter('type', $filterType)
42+
->executeQuery();
43+
44+
return (bool) $result->rowCount();
45+
}
46+
2547
/* ============================= *
2648
* CONFIG *
2749
* ============================= */

src/Engine/Context/ValidationContext.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(
2929
private ?\Closure $entryCache = null,
3030
#[Assert\PositiveOrZero] public int $jumpToReaderPageId = 0,
3131
#[Assert\PositiveOrZero] public int $jumpToListViewPageId = 0,
32-
#[Assert\NotBlank] private string $autoItemField = 'id',
32+
#[Assert\NotBlank] public string $autoItemField = 'id',
3333
private array $filterValues = [],
3434
) {
3535
$this->paginatorConfig = new PaginatorConfig(itemsPerPage: 1);
@@ -48,11 +48,6 @@ public function createBackLink(): ?BackLink
4848
return BackLink::fromPage($pageModel);
4949
}
5050

51-
public function getAutoItemField(): string
52-
{
53-
return $this->autoItemField;
54-
}
55-
5651
public function getEntryCache(): array
5752
{
5853
if (!\is_callable($this->entryCache)) {
@@ -94,4 +89,4 @@ public function withFilterValues(array $values): self
9489
filterValues: $values,
9590
);
9691
}
97-
}
92+
}

src/Engine/Loader/ValidationLoaderConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
readonly class ValidationLoaderConfig
1111
{
1212
public function __construct(
13-
public ListSpec $list,
13+
public ListSpec $list,
1414
public ValidationContext $context,
1515
public string $autoItemField,
1616
) {}
17-
}
17+
}

src/Engine/Projector/AbstractProjector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
use Doctrine\DBAL\Query\QueryBuilder;
88
use HeimrichHannot\FlareBundle\Engine\Context\ContextInterface;
9+
use HeimrichHannot\FlareBundle\Engine\Factory\LoaderFactory;
910
use HeimrichHannot\FlareBundle\Engine\View\ViewInterface;
1011
use HeimrichHannot\FlareBundle\Exception\FilterException;
1112
use HeimrichHannot\FlareBundle\Exception\FlareException;
1213
use HeimrichHannot\FlareBundle\List\ListSpec;
1314
use HeimrichHannot\FlareBundle\Query\Executor\ListQueryDirector;
1415
use HeimrichHannot\FlareBundle\Query\ListQueryConfig;
16+
use HeimrichHannot\FlareBundle\Reader\Factory\ReaderUrlGeneratorFactory;
1517
use HeimrichHannot\FlareBundle\Registry\ProjectorRegistry;
1618
use Psr\Container\ContainerExceptionInterface;
1719
use Psr\Container\ContainerInterface;
@@ -35,7 +37,9 @@ public static function getSubscribedServices(): array
3537
{
3638
return [
3739
ListQueryDirector::class,
40+
LoaderFactory::class,
3841
ProjectorRegistry::class,
42+
ReaderUrlGeneratorFactory::class,
3943
RequestStack::class,
4044
];
4145
}
@@ -67,6 +71,16 @@ protected function getListQueryDirector(): ListQueryDirector
6771
return $this->container->get(ListQueryDirector::class);
6872
}
6973

74+
protected function getLoaderFactory(): LoaderFactory
75+
{
76+
return $this->container->get(LoaderFactory::class);
77+
}
78+
79+
protected function getReaderUrlGeneratorFactory(): ReaderUrlGeneratorFactory
80+
{
81+
return $this->container->get(ReaderUrlGeneratorFactory::class);
82+
}
83+
7084
/**
7185
* @throws FlareException
7286
*/

src/Engine/Projector/AggregationProjector.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use HeimrichHannot\FlareBundle\Engine\Context\AggregationContext;
88
use HeimrichHannot\FlareBundle\Engine\Context\ContextInterface;
9-
use HeimrichHannot\FlareBundle\Engine\Factory\LoaderFactory;
109
use HeimrichHannot\FlareBundle\Engine\Loader\AggregationLoaderConfig;
1110
use HeimrichHannot\FlareBundle\Engine\Loader\AggregationLoaderInterface;
1211
use HeimrichHannot\FlareBundle\Engine\View\AggregationView;
@@ -17,10 +16,6 @@
1716
*/
1817
class AggregationProjector extends AbstractProjector
1918
{
20-
public function __construct(
21-
private readonly LoaderFactory $loaderFactory,
22-
) {}
23-
2419
public function supports(ListSpec $list, ContextInterface $context): bool
2520
{
2621
return $context instanceof AggregationContext;
@@ -41,11 +36,11 @@ public function project(ListSpec $list, ContextInterface $context): AggregationV
4136

4237
protected function createLoader(AggregationLoaderConfig $config): AggregationLoaderInterface
4338
{
44-
return $this->loaderFactory->createAggregationLoader($config);
39+
return $this->getLoaderFactory()->createAggregationLoader($config);
4540
}
4641

4742
protected function createView(AggregationLoaderInterface $loader): AggregationView
4843
{
4944
return new AggregationView(loader: $loader);
5045
}
51-
}
46+
}

src/Engine/Projector/InteractiveProjector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class InteractiveProjector extends AbstractProjector
3232
public function __construct(
3333
private readonly AggregationContextFactory $aggregationConfigFactory,
3434
private readonly FilterFormFactory $filterFormFactory,
35-
private readonly LoaderFactory $loaderFactory,
3635
private readonly PaginatorFactory $paginatorFactory,
37-
private readonly ReaderUrlGeneratorFactory $readerUrlGeneratorFactory,
3836
) {}
3937

4038
public function supports(ListSpec $list, ContextInterface $context): bool
@@ -72,7 +70,8 @@ public function project(ListSpec $list, ContextInterface $context): InteractiveV
7270
$loader = $this->createLoader($config);
7371
}
7472

75-
$readerUrlGenerator = $this->readerUrlGeneratorFactory->create($context->createReaderUrlConfig());
73+
$readerUrlConfig = $context->createReaderUrlConfig();
74+
$readerUrlGenerator = $this->getReaderUrlGeneratorFactory()->create($readerUrlConfig);
7675

7776
return $this->createView(
7877
loader: $loader,
@@ -86,7 +85,7 @@ public function project(ListSpec $list, ContextInterface $context): InteractiveV
8685

8786
protected function createLoader(InteractiveLoaderConfig $config): InteractiveLoaderInterface
8887
{
89-
return $this->loaderFactory->createInteractiveLoader($config);
88+
return $this->getLoaderFactory()->createInteractiveLoader($config);
9089
}
9190

9291
protected function createView(

src/Engine/Projector/ValidationProjector.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
*/
2121
class ValidationProjector extends AbstractProjector
2222
{
23-
public function __construct(
24-
private readonly LoaderFactory $loaderFactory,
25-
private readonly ReaderUrlGeneratorFactory $readerUrlGeneratorFactory,
26-
) {}
27-
2823
public function supports(ListSpec $list, ContextInterface $context): bool
2924
{
3025
return $context instanceof ValidationContext;
@@ -35,15 +30,15 @@ public function project(ListSpec $list, ContextInterface $context): ValidationVi
3530
\assert($context instanceof ValidationContext, '$config must be an instance of ValidationConfig');
3631

3732
$readerUrlConfig = $context->createReaderUrlConfig();
38-
$autoItemField = $readerUrlConfig->autoItemField ?? $context->getAutoItemField();
33+
$autoItemField = $readerUrlConfig->autoItemField ?? $context->autoItemField;
3934

4035
$loader = $this->createLoader(new ValidationLoaderConfig(
4136
list: $list,
4237
context: $context,
4338
autoItemField: $autoItemField,
4439
));
4540

46-
$readerUrlGenerator = $this->readerUrlGeneratorFactory->create($readerUrlConfig);
41+
$readerUrlGenerator = $this->getReaderUrlGeneratorFactory()->create($readerUrlConfig);
4742

4843
return $this->createView(
4944
loader: $loader,
@@ -56,7 +51,7 @@ public function project(ListSpec $list, ContextInterface $context): ValidationVi
5651

5752
protected function createLoader(ValidationLoaderConfig $config): ValidationLoaderInterface
5853
{
59-
return $this->loaderFactory->createValidationLoader($config);
54+
return $this->getLoaderFactory()->createValidationLoader($config);
6055
}
6156

6257
protected function createView(

0 commit comments

Comments
 (0)