Skip to content

Commit e178531

Browse files
author
Vladimir Falcón Piva
committed
Add HeaderSoftHyphen processor to handle soft hyphens in headers
1 parent 6d4004d commit e178531

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

Classes/DataProcessing/HeaderDataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\FrameClassProcessor;
88
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLayoutProcessor;
99
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLinkProcessor;
10+
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderSoftHyphen;
1011
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeadlinesProcessor;
1112
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\PassThrough;
1213
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\SpaceBeforeProcessor;
@@ -25,7 +26,7 @@ class HeaderDataProcessor extends TtContentDataProcessor implements FieldMapping
2526
use FieldMappingTrait;
2627

2728
public const DEFAULT_FIELDS = [
28-
self::FIELD_HEADER => PassThrough::class,
29+
self::FIELD_HEADER => HeaderSoftHyphen::class,
2930
self::FIELD_SUBHEADER => PassThrough::class,
3031
self::FIELD_HEADER_LAYOUT => HeaderLayoutProcessor::class,
3132
// note: `header_link` must be processed before `headlines`

Classes/DataProcessing/TextMediaDataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\FrameClassProcessor;
1111
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLayoutProcessor;
1212
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLinkProcessor;
13+
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderSoftHyphen;
1314
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeadlinesProcessor;
1415
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\ImageBelowTextProcessor;
1516
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\ImageOrientProcessor;
@@ -35,7 +36,7 @@ class TextMediaDataProcessor extends TtContentDataProcessor implements FieldMapp
3536
public const DEFAULT_FIELDS = [
3637
self::FIELD_ASSETS => MediaProcessor::class,
3738
self::FIELD_BODYTEXT => BodytextProcessor::class,
38-
self::FIELD_HEADER => PassThrough::class,
39+
self::FIELD_HEADER => HeaderSoftHyphen::class,
3940
self::FIELD_HEADER_LAYOUT => HeaderLayoutProcessor::class,
4041
self::FIELD_HEADER_LINK => HeaderLinkProcessor::class,
4142
self::FIELD_HEADLINES => HeadlinesProcessor::class,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field;
6+
7+
use Cpsit\BravoHandlebarsContent\DataProcessing\FieldProcessorInterface;
8+
9+
/*
10+
* This file is part of the bravo handlebars content package.
11+
*
12+
* It is free software; you can redistribute it and/or modify it under
13+
* the terms of the GNU General Public License, either version 2
14+
* of the License, or any later version.
15+
*/
16+
17+
/**
18+
* Class PassThrough
19+
*
20+
* This processor just returns the value of a given field in the data array
21+
*/
22+
class HeaderSoftHyphen implements FieldProcessorInterface
23+
{
24+
use FieldProcessorConfigTrait;
25+
26+
public function process(string $fieldName, array $data, array $variables): array
27+
{
28+
if (isset($data[$fieldName])) {
29+
$sanitizedData = htmlspecialchars((string)$data[$fieldName], ENT_COMPAT, 'UTF-8', false);
30+
$variables[$fieldName] = str_replace('--', '&shy;', $sanitizedData);
31+
}
32+
33+
return $variables;
34+
}
35+
}

Classes/DataProcessing/TtContentDataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\FrameClassProcessor;
1919
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLayoutProcessor;
2020
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLinkProcessor;
21+
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderSoftHyphen;
2122
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeadlinesProcessor;
2223
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\PassThrough;
2324
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\SpaceBeforeProcessor;
@@ -36,7 +37,7 @@ class TtContentDataProcessor implements DataProcessorInterface, FieldAwareProces
3637

3738
public const DEFAULT_FIELDS = [
3839
self::FIELD_BODYTEXT => BodytextProcessor::class,
39-
self::FIELD_HEADER => PassThrough::class,
40+
self::FIELD_HEADER => HeaderSoftHyphen::class,
4041
self::FIELD_HEADER_LAYOUT => HeaderLayoutProcessor::class,
4142
// note: `header_link` must be processed before `headlines`
4243
self::FIELD_HEADER_LINK => HeaderLinkProcessor::class,

Classes/DataProcessing/UploadsDataProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\FrameClassProcessor;
1616
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLayoutProcessor;
1717
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderLinkProcessor;
18+
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeaderSoftHyphen;
1819
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\HeadlinesProcessor;
1920
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\PassThrough;
2021
use Cpsit\BravoHandlebarsContent\DataProcessing\TtContent\Field\SpaceBeforeProcessor;
@@ -25,7 +26,7 @@ class UploadsDataProcessor extends TtContentDataProcessor implements FieldMappin
2526
use FieldMappingTrait;
2627

2728
public const DEFAULT_FIELDS = [
28-
self::FIELD_HEADER => PassThrough::class,
29+
self::FIELD_HEADER => HeaderSoftHyphen::class,
2930
self::FIELD_HEADER_LAYOUT => HeaderLayoutProcessor::class,
3031
self::FIELD_HEADER_LINK => HeaderLinkProcessor::class,
3132
self::FIELD_HEADLINES => HeadlinesProcessor::class,

0 commit comments

Comments
 (0)